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

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

问题描述

我有许多 ASP.NET Web 窗体网站(没有 .csproj 文件的网站),我正在尝试弄清楚如何最好地将 NuGet 包与它们一起使用.使用 Visual Studio 2015 时,通过 UI 添加 NuGet 包可以正常工作(站点根目录中有一个 packages.config),并且构建会将二进制文件放到 bin 文件夹中.

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

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

解决方案

一段时间后,我有了一个解决方法,可以让我到达我需要的地方,尽管不是最好的方法.

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

让它在 CI 服务器上构建的方法是:

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

这不是一个很好的解决方案,因为我现在必须多次调用 NuGet restore(一次用于解决方案,一次用于每个网站),但它确实有效.我不知道支持多远的 .refresh 文件,但它在 2015 年确实有效.我可能会在 NuGet 中提出更改请求,以允许通过命令行传入多个解决方案/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 服务器上的 ASP.NET 网站中使用 NuGet 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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