如何在 CI 服务器上的 ASP.NET 网站中使用 NuGet 包

编程入门 行业动态 更新时间:2024-10-14 00:26:37
本文介绍了如何在 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 服务器上构建的方法是:

  • 忽略(.gitignore、.hgignore)网站的 bin 文件夹
  • 在 bin 文件夹中显式添加 .refresh 文件
  • 在实际构建之前,调用 NuGet restore,将路径传递到网站的 packages.config 并将 PackagesDirectory(或 SolutionDirectory)设置为解决方案的包文件夹
  • 预编译,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:

  • Ignore (.gitignore, .hgignore) the website's bin folder
  • Explicitly add the .refresh file(s) in the bin folder
  • 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
  • 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 包

    本文发布于:2023-06-11 03:53:28,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/626210.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:器上   如何在   网站   ASP   CI

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!