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

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

问题描述

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

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.

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

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.

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

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.

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

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.

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

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

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

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

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.

谢谢,埃里克

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

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