在构建期间无法自动将 NuGet 包更新到最新版本 [英] Cannot automatically update a NuGet package to the latest version during build

查看:19
本文介绍了在构建期间无法自动将 NuGet 包更新到最新版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有两个独立的 .NET 解决方案:

We have two separate .NET solutions:

  • 为第一个解决方案运行构建会生成我们的最终产品:一堆 DLL.这些 DLL 通过 NuGet 包交付给我们的客户.
  • 第二个解决方案用作产品测试解决方案:将 NuGet 包安装到其中,并构建和执行它 - 因此它使用我们的产品的方式与我们的客户使用的方式完全相同.

这里的挑战是我们最新的 NuGet 包应该有一种方法自动安装到产品测试解决方案中,最好是在构建这个产品测试解决方案期间.

The challenge here is that there should be a way our latest NuGet package gets installed automatically to the product-test solution, preferably during the build of this product-test solution.

基于 类似问题的想法,我在配置产品测试解决方案方面做到了这一点:

Based on the ideas from a similar question, I got this far with configuring the product-test solution:

  • 首先我启用了 NuGet 包还原.这让我完全摆脱了 VCS 中的packages"目录,因为具有 packages.config 文件中定义的版本的包将在构建之前由 NuGet 自动下载.
  • 然后我在 Visual Studio 中添加了以下预构建事件:$(SolutionDir).nuget uget update -prerelease $(ProjectDir)packages.config.这让我可以在构建过程中引入最新版本的 NuGet 包.
  • First I enabled NuGet Package Restore. This lets me get rid of the "packages" directory completely from VCS since the package with the version defined in packages.config file would be downloaded automatically by NuGet before build.
  • Then I added the following pre-build event in Visual Studio: $(SolutionDir).nuget uget update -prerelease $(ProjectDir)packages.config. This lets me pull in the latest version of our NuGet package during build.

我目前使用上述方案来运行使用 Visual Studio 的本地构建和使用 TeamCity 的无人值守构建.该解决方案乍一看似乎适用于这两种情况,但实际上它不会产生预期的结果:构建产品测试解决方案时,在 bin 目录中我没有最新版本的 DLL,只有 latest-1 版本.

I currently use the above scenario to run local builds using Visual Studio and unattended builds using TeamCity. The solution seems to work for both scenarios on the first sight, but actually it does not produce the expected result: when the product-test solution is built, in the bin directory I don't get the latest version of the DLLs, only the latest-1 version.

问题在于,尽管 nuget update 命令会按预期更新所有内容,包括 packages.config.csproj 文件,但它们的new content 不会被构建拾取,因此 - 正如我的猜测 - .csproj 文件中的 HintPath 设置仍然反映"before build"状态,因此旧的 DLL 被复制到 bin 目录.我假设 .csproj 文件只处理一次:在触发预构建事件之前,并且预构建事件所做的更改在下一次构建之前被忽略.

The problem is that although the nuget update command updates everything as expected, including the packages.config and the .csproj file, their new content is not picked up by the build, therefore - as my guess goes - the HintPath settings from the .csproj file still reflect a "before build" state, therefore old DLLs are copied to the bin directory. I assume the .csproj file is processed only once: before the pre-build event is triggered, and the changes made by the pre-build event are ignored until the next build.

我考虑了以下解决方案:

I considered the following solutions:

  • 显然预构建还不够预".如果有更早一点我可以插入 nuget update 命令,我上面的解决方案可能会起作用.
  • 我读到我可以通过定义 ReferencePath 来覆盖 .csproj 文件中的 HintPath-s.但我怀疑我能否轻松找出正确的路径,或者我是否可以及早设置它,以便构建能够接受它.
  • 作为一种解决方法,我可以运行构建两次:在 TeamCity 中为产品测试解决方案复制构建步骤,我总是可以在 Visual Studio 中本地构建解决方案两次.
  • Apparently pre-build is not "pre" enough. If there was an even earlier point I could insert the nuget update command, my above solution would probably work.
  • I read that I could override the HintPath-s in the .csproj file by defining a ReferencePath. But I doubt I could easily figure out the right path or I could set it early enough so the build picks it up.
  • As a workaround I could run the builds twice: duplicate the build step for the product-test solution in TeamCity and I could always build the solution twice locally in Visual Studio.

有人知道如何在构建过程中自动将 NuGet 包更新到最新版本吗?

Has someone figured out how to automatically update a NuGet package to the latest version during build?

推荐答案

看看我刚刚写的关于这个过程的博客文章.我没有在服务器上配置东西,而是通过扩充 Nuget.Targets 文件来完成此操作,该文件使用 Nuget 包还原选项放置到位.这种方法的美妙之处在于它在本地和服务器上执行(因此您可以在破坏构建之前看到任何可能的副作用)

Have a look at a blog post I just did regarding this process. Instead of configuring stuff on the server, I did it by augmenting the Nuget.Targets file that's put in place with the Nuget Package Restore option. Beauty of this approach is it executes locally AND on the server (so you get to see any possible side-effects before breaking the build)

在此处发布详细信息:http://netitude.bc3tech.net/2014/11/28/auto-update-your-nuget-packages-at-build-time/

这篇关于在构建期间无法自动将 NuGet 包更新到最新版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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