Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent NuGet Restore Package in debug builds only

I enabled the Restore Package option in my solution so when I upload the code to the CI server it updates all the packages that it needs to build correctly, and it works great. Now the problem is that on my local machine, the build takes a long time to start because is "updating the packages". Is there a way to enable the Restore Package in release build only?

I've tried to move the <RestorePackage> property in the .csproj files to the release/debug sections with false and true, but NuGet updates the attribute when a open the NuGet console and resets both to true; also tried to only include the property in the release section, but then NuGet adds it to the global section... so I had no luck making it stay the way I want it...

Any advice?

like image 855
Jaime Avatar asked Feb 14 '12 01:02

Jaime


1 Answers

You have probably managed to answer this by now but if not then these are the steps you need to follow

Right where your solution file is within Windows there should be a folder named .nuget. Either rename or delete this folder.

Now open each .csproj or .vbproj file in notepad or any text editor and remove these lines

<RestorePackages>true</RestorePackages>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" />

The important part is removing/renaming the .nuget folder. This should now disable package restore completely.

Edit: To selectively disable package restore for DEBUG builds edit the Nuget.settings.targets file and modify the following line

<RestorePackages Condition="$(RestorePackages) == ''">false</RestorePackages>

To

<RestorePackages Condition="$(RestorePackages) == '' AND '$(Configuration)' == 'Debug'">false</RestorePackages>

The Nuget.settings.targets file is under the .nuget folder which should be in the same folder as your solution file.

like image 188
Nikhil Avatar answered Dec 23 '22 07:12

Nikhil