如何在CI Server上的ASP.NET网站上使用NuGet软件包 [英] How to use NuGet packages with an ASP.NET Website on CI Server

查看:72
本文介绍了如何在CI Server上的ASP.NET网站上使用NuGet软件包的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多ASP.NET Web表单网站(一个没有.csproj文件的网站),并且我试图弄清楚如何最好地与它们一起使用NuGet软件包.使用Visual Studio 2015时,通过UI添加NuGet程序包可以正常工作(网站根目录中有packages.config),并且该版本将二进制文件拖放到bin文件夹中.

问题是试图通过MSBuild在TeamCity上构建项目.对于其他项目,我可以将NuGet.exe与restore命令一起使用(针对csproj或sln文件),并且软件包已正确下载并包含在输出中.但是,这不适用于网站,因此由于缺少文件而导致编译失败.

作为最后的选择,我可以编写一个自定义脚本/构建步骤以将程序集手动复制到bin文件夹,但是我想避免这种情况.我想念什么吗?是否可以在Visual Studio之外的网站上使用NuGet?

解决方案

过一段时间后,我有了一种解决方法,即使不是最佳方法,该解决方法也可以使我到达需要的位置.

在较新版本的Visual Studio中,当通过VS将二进制依赖项添加到网站时,它将在二进制文件旁边将(binaryfile).dll.refresh文件添加到bin文件夹中.该文件的内容是通过解决方案的packages文件夹到.dll的相对路径.此外,packages.config文件已添加到网站.

将其构建在CI服务器上的方法是:

  1. 忽略(.gitignore,.hgignore)网站的bin文件夹
  2. 将.refresh文件明确添加到bin文件夹中
  3. 在实际构建之前,调用NuGet恢复,将路径传递到网站的packages.config,并将PackagesDirectory(或SolutionDirectory)设置为解决方案的packages文件夹
  4. 预编译,MSBuild将打开每个刷新文件,并从文件中包含的位置复制文件.

这不是一个很好的解决方案,因为我现在不得不多次调用NuGet restore(一次解决方案,每个网站一次),但是它确实有效.我不知道支持.refresh文件多久,但它在2015年确实可以工作.我可能会在NuGet中发出更改请求,以允许通过命令行传递多个solution/packages.configs.

谢谢,埃里克

I have a number of ASP.NET Web Form Websites (the one with no .csproj file), and I am trying to figure out how to best use NuGet packages with them. When using Visual Studio 2015, adding NuGet packages via the UI works correctly (there is a packages.config in the site root), and the build drops the binaries in the bin folder.

The problem is trying to build the project on TeamCity via MSBuild. For other projects, I can use NuGet.exe with the restore command (either against the csproj or the sln file), and the packages are correctly downloaded and included in the output. However, this doesn't work with the websites, and thus the compile fails due to missing files.

As a last resort, I could write a custom script/build step to manually copy the assemblies to the bin folder, but I'd like to avoid this. Am I missing something? Is there any way to use NuGet with websites outside of Visual Studio?

解决方案

After some time, I have a workaround that gets me where I need to be, albeit not in the best way.

In newer versions of Visual Studio, when a binary dependency is added to a website via VS, it adds a (binaryfile).dll.refresh file to the bin folder alongside the binary file. The contents of the file is the relative path to the .dll via the packages folder for the solution. In addition, a packages.config file is added to the website.

The way to get it to build on a CI server is:

  1. Ignore (.gitignore, .hgignore) the website's bin folder
  2. Explicitly add the .refresh file(s) in the bin folder
  3. Prior to the actual build, call NuGet restore, passing in the path to the website's packages.config and setting the PackagesDirectory (or SolutionDirectory) to the packages folder for the solution
  4. Pre-Compile, MSBuild will open each refresh file, and copy the file from the location contained in the file.

It's not a great solution, because I now have to call NuGet restore multiple times (once for solution, once for each website), but it does work. I don't know how far back the .refresh file is supported, but it does work in 2015. I may make a change request in NuGet to allow for multiple solutions/packages.configs to be passed in via the command line.

Thanks, Erick

这篇关于如何在CI Server上的ASP.NET网站上使用NuGet软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆