Restoring a NuGet package * without * changing each project in the solution to import the NuGet.targets MsBuild task

Restoring a NuGet package seems like the right way to combine NuGet with source control (TFS in my case), for example in this answer and in the first comment on this closed question . Restoring a NuGet package allows you to retrieve a solution from the source and build it on another development machine to automatically download the required NuGet packages.

To add NuGet Package Restore to a solution, right-click on the solution and then select Enable NuGet Package Restore. This "added a folder called .nuget containing NuGet.exe and the NuGet.targets MsBuild file, and changed every project in the solution to import the NuGet.targets MsBuild task." (Quoted from http://docs.nuget.org/docs/Workflows/Using-NuGet-without-committing-packages ). But some of the projects in the solution I'm working on are useful projects that are shared between different solutions and between different developers, and they don't need references handled by NuGet.

How do I enable NuGet package restore, but exclude certain projects in the solution from the NuGet build task setting?

+3


source to share


2 answers


NuGet Package Restore currently has some limitations and cannot be limited to specific projects. There's an existing NuGet work item to make this possible: # 1812 - Enable Package Restore - Selective Projects

Please comment / vote for it to increase the priority as it is not currently registered.



Note: On the surface, .csproj files seem to have a property to support disabling NuGet package restore, but due to another issue it keeps returning: NuGet command line forcibly restores package

+4


source


You can run the script from the PreBuild stage of the first project to be built, which loops through all the files packages.config

and loads their content. You need to call

.nuget/nuget.exe install "....\packages.config" -o "packages"

      

from yours $(SolutionDir)

to everyone packages.config

in your decision.



This will work better than the default solution as it will also download solution level packages that are not installed in the project.

On my builds server, I use this snippet (shell):

find -iname packages.config -print0 | xargs -0 -ti mono --runtime=v4.0.30319 .nuget/nuget.exe install {} -o "packages"

      

+1


source







All Articles