Reputation: 13778
I'm using NuGet to manage dependencies. I really like NuGet and it has made a number of things much simpler for me.
In Visual Studio, I use the automatic package restore feature so that packages are updated during the build. I've also found a way to have the nuget.exe file download itself if it is missing. This is brilliant, it means developers can check out the source and just build it. It makes dependency management almost a 'no-brainer'.
However, I'm having a problem with TeamCity CI builds. When building in TeamCity, I prefer to use TC's NuGet Installer build step. I find this gives me more intuitive control of the build process and it means I can specify the package sources I want to use. However, this conflicts somewhat with the NuGet automatic restore, because it downloads nuget.exe and tries to update all the packages again.
The build does work but I could improve efficiency by avoiding the second NuGet update operation, which can take some time if there are a lot of dependencies. What I need is a way to thwart the auto-restore only when it is running on the build server. Has anyone thought of a way to do that?
Upvotes: 1
Views: 1609
Reputation: 20324
Nuget 2.7 uses a newer method for package restore.
This answer is for Nuget < 2.7:
NuGet package restore is triggered by the following line in each of your csproj files:
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
If you take a look inside $(SolutionDir)\.nuget\nuget.targets
, you'll see almost at the top a line such as this:
<RestorePackages Condition=" '$(RestorePackages)' == '' ">true</RestorePackages>
What this means, is that if no variable RestorePackages
can be found (or its value is empty), it will default to true
and automatically restore missing packages during the build.
To prevent the package restore step, in the TeamCity build configuration, create a system property named system.RestorePackages
with a value of false
, like so:
Upvotes: 7