Reputation: 34396
When enabling NuGet package restore, it adds the following to my solution:
/.nuget
/.nuget/NuGet.exe
/.nuget/NuGet.targets
As these are part of my solution, committing the solution to my repository without either of these files means I'll have missing references in my solution, but removing the folder or either of these files means NuGet package restore is not enabled.
Given that part of the point of setting up package restore is so that I don't have to commit binaries to the repository, what is the intention behind forcing NuGet.exe into the solution?
Is the assumption that committing one small .exe to the repository is a small price to pay to remove the need to commit other binaries? Or am I supposed to exclude these from the repository also and tell a developer checking out my repository for the first time to go and enable package restore? What about when continuous integration encounters a missing reference in my solution?
Upvotes: 19
Views: 12298
Reputation: 14810
The point behind committing the .nuget folder to the repository is that you can set up your solution to use package restore, using the exact same version of nuget.exe you installed when enabling this feature.
Your project files depend on the nuget.targets MSBuild instructions that use nuget.exe, and both files are considered linked together because the MSBuild instructions use the nuget.exe API. It's perfectly possible to end up with a different version of nuget.exe and nuget.targets one day. It uses the NuGet.Build and NuGet.Commandline packages under the hood. That's also the reason why package restore is typically set up once for the solution, and not by every developer individually.
Also, you won't need to install nuget.exe on each build server, and your build server can build solutions with different versions of nuget.exe, which is an added benefit that requires no additional effort. And yes, one could consider it a small price to pay as well :-)
If your CI encounters a missing reference, check the following:
Upvotes: 14
Reputation: 25070
For .gitignore
, add below lines.
.nuget/
!.nuget/packages.config
Upvotes: 2
Reputation: 4947
If you are following @Richard Szalay's answer (not committing nuget.exe), and for some reasons Visual Studio does not automatically download the nuget.exe, make sure you have the following set to true in the nuget.targets file:
<!-- Download NuGet.exe if it does not already exist -->
<DownloadNuGetExe Condition=" '$(DownloadNuGetExe)' == '' ">true</DownloadNuGetExe>
Close the VS solution, reopen it and build it. Visual Studio should download nuget.exe automatically now.
Upvotes: 8
Reputation: 84784
You don't have to commit nuget.exe to source control. NuGet.targets downloads the latest NuGet.exe from nuget.org if it's missing.
Upvotes: 9