We have two separate .NET solutions:
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:
$(SolutionDir).nuget\nuget update -prerelease $(ProjectDir)packages.config
. This lets me pull in the latest version of our NuGet package during build.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.
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
command, my above solution would probably work.Has someone figured out how to automatically update a NuGet package to the latest version during build?
Right-click the Packages folder in the project, and select Update. This will update the NuGet package to the latest version. You can double-click the Add packages and choose the specific version.
Open NuGet Package Manager, go to the package, and uninstall (it should show the new version that you modified the packages. config file to). In NuGet Package Manager, go to the browse tab, find the package you just uninstalled, then install it again.
Switch to the Browse tab, search for the package name, select it, then select Install). For all packages, delete the package folder, then run nuget install . For a single package, delete the package folder and use nuget install <id> to reinstall the same one.
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)
Posted details here: http://netitude.bc3tech.net/2014/11/28/auto-update-your-nuget-packages-at-build-time/
I think that put automatic update to pre-build step it's not NuGet style. You can understand that you need this operation every time when you do it. Mostly because it can increase build time. For example when you use TDD and often rebuild project and run tests, you expect that it will be done quickly. Additionally it can update unexpected packages and break something, after that you can spend a lot of time to find the problem.
I suggest to do update as the separate step. On TeamCity you can use NuGet installer
build step. For performing update just check two checkboxes in the bottom area of step configuration:
Additionally if you want keep result of update after successful build and passing test, you can add later build step which commits this changes to VCS (using cmd or PowerShell for example).
When you are working locally, I thing the better way run update packages once before you start working with project. You can use Package Manager Console
for this, with command Update-Package -IncludePrerelease
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With