1

I have a project(s) that I'm writing NUnit tests for (for example). I want to commit the code to git, but I also feel it's bad practice to commit the NuGet packages (NUnit and NUnit.Runner) to the repo. However, I don't want to also turn on Package restore either since I believe it's a user setting and not a project setting (IIRC).

What is the right way to add .NET project with NuGet dependencies to a git repo? I assume it would be something that would happily grab the Packages but one that requires developer intervention. Perhaps just expect other developers to know to add those missing packages back into the project? (It also seems like we'd end up resolving .csproj conflicts all the time too).

lucidquiet
  • 6,124
  • 7
  • 51
  • 88

2 Answers2

3

You should add your solution's packages.config file only to your git repo. From it every developper will be able to install needed package automatically.

For example, under Visual Studio 2012 at least, you can check the 'Allow NuGet to download missing packages during build' checkbox in the 'Package Manager Settings' window accessible under the 'Tools' > 'Library Package Manager' menu. With this option and the packages.config file you have nothing else to do...

Yannick Blondeau
  • 9,465
  • 8
  • 52
  • 74
2

If unable or unwilling to enable package restore, a developer can easily add all packages by command line, as explained in this question:

You can use nuget.exe to restore your packages. Run the following command for each project.

nuget install packages.config

You can also run this in a pre-build command, as explained here:

$(SolutionDir)Tools\nuget install $(ProjectDir)packages.config

But really, package restore is easier, it merely requires a few clicks.

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • I forgot about this -- I could actually add a script (.bat) to the project for reloading the packages, and add a setup instruction to the readme stating that the project needs nuget.exe installed and on the classpath. – lucidquiet Jan 23 '13 at 22:26
  • I prefer not to use package restore for 3 reasons. First, I want to run a build from the command line from a fresh checkout, possibly part of some kind of CI. Second, IIRC package restore is a system/user setting which I believe means that the package restore is turned on for a user on a machine instead of for a specific project. And third IIRC turning off package restore isn't simple. Maybe it is better in VS 2012. I don't have VS 2012 yet, and most everyone I work with only has 2010 (right now). – lucidquiet Jan 24 '13 at 00:36
  • Based on the link, the suggestion is to commit nuget.exe under tools, but won't this not work if the system needs to run on both 32 and 64 bit -- because NuGet exe will be built for a 32/64bit target? – lucidquiet Jan 24 '13 at 19:47