3

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?

Community
  • 1
  • 1
dumbledad
  • 16,305
  • 23
  • 120
  • 273

2 Answers2

4

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

Alexandre Dion
  • 9,130
  • 2
  • 41
  • 29
  • +1 for the vote suggestion. Thanks for the informative answer. – dumbledad Apr 04 '12 at 06:40
  • Alexandre, I notice from that work item that one way round is to run the NuGet Package Restore on the solution and then manually revert the projects that you do not want changed to their previous versions. Is this a good workaround? – dumbledad Apr 04 '12 at 08:45
  • 1
    I believe this won't work at the moment because of the note I added in the response. Specifically [this issue](http://nuget.codeplex.com/workitem/1998), causing restore to be switched on every project because EnablePackageRestore is called when NuGet gets initialized. – Alexandre Dion Apr 04 '12 at 16:04
1

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"
David Schmitt
  • 58,259
  • 26
  • 121
  • 165