We have two separate .NET solutions:
- Running a build for the first solution produces our end product: a bunch of DLLs. These DLLs are delivered to our customers via a NuGet package.
- The second solution serves as a product-test solution: the NuGet package is installed to it, and it is built and executed - thus it makes use of our product exactly the same way as our customers would do.
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:
- 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.
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:
- 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.
Has someone figured out how to automatically update a NuGet package to the latest version during build?