问题描述
我们有两个单独的.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"目录,因为在构建之前,NuGet会自动下载具有packages.config文件中定义的版本的软件包.
- 然后,我在Visual Studio中添加了以下预构建事件:
$(SolutionDir).nuget\nuget 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\nuget update -prerelease $(ProjectDir)packages.config
. This lets me pull in the latest version of our NuGet package during build.
我目前使用上述方案在Visual Studio中运行本地版本,在TeamCity中运行无人值守版本.解决方案乍一看似乎适用于这两种情况,但实际上它不会产生预期的结果:构建产品测试解决方案时,在bin
目录中我看不到DLL的最新版本,只有最新的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
文件,但是它们的新内容未被构建所拾取,因此-就像我猜测的那样-.csproj
文件中的 HintPath 设置仍然反映生成前"状态,因此将旧的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 Package Restore选项放置的Nuget.Targets文件来实现的.这种方法的优点在于它可以在服务器上本地执行(这样您就可以在破坏构建之前了解所有可能的副作用)
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/
Posted details here: http://netitude.bc3tech.net/2014/11/28/auto-update-your-nuget-packages-at-build-time/
这篇关于在构建过程中无法自动将NuGet软件包更新为最新版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!