3
votes

NuGet Package Restore seems to be the correct way to combine NuGet with source-control (in my case TFS), for example in this answer and in the first comment to this closed question. NuGet Package Restore allows a solution fetched from source-control and built on another dev' machine to automatically fetch the required NuGet packages.

To add NuGet Package Restore to a solution you right click on the solution and then select Enable NuGet Package Restore. That "added a solution folder named .nuget containing NuGet.exe and a NuGet.targets MsBuild file. It also changed every project in the solution to import the NuGet.targets MsBuild task." (Quote from http://docs.nuget.org/docs/Workflows/Using-NuGet-without-committing-packages). But some of the projects in the solution I am working on are utility projects, shared between different solutions and between different developers and they do not require references handled by NuGet.

How do I enable NuGet Package Restore but preclude certain projects in the solution from the NuGet build task set-up?

2

2 Answers

4
votes

At the moment, NuGet Package Restore has some limitations and can't be restricted to specific projects. There's an existing NuGet work item that would make this possible : #1812 - Enable Package Restore - Selective Projects

Please comment/vote on it to bump the priority since it's currently backlogged.

Note: at the surface, .csproj files appears to have a property to support turning off NuGet Package Restore, but due to another issue, it keeps turning back on : NuGet command line forces package restore

1
votes

You can run a script from the PreBuild step of the first project to be built that walks through all packages.config files and downloads their contents. You need to call

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

from your $(SolutionDir) for every packages.config in your solution.

This will actually work better than the standard solution, since it'll also download solution-level packages, that are not installed into a project.

On my buildserver I use this (shell) snippet:

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