Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should .nuget folder be added to version control?

With newer versions of NuGet it is possible to configure a project to automatically restore NuGet packages so that the packages folder doesn't need to be included in the source code repository. Good.

However, this command adds a new .nuget folder and there is a binary there, NuGet.exe. This can also be re-created automatically by Visual Studio and so it doesn't feel correct to add that to version control. However, without this folder Visual Studio won't even load the solution properly.

How do you people deal with this? Add .nuget to source control? Run some command line script before opening the solution?

like image 995
Borek Bernard Avatar asked Feb 05 '12 01:02

Borek Bernard


People also ask

Do I need .NuGet folder?

nuget folder is used as a cache for packages downloaded to speed up project restore and compilation. It can safely be removed. Worst case, it will have to download the packages again in the future. Save this answer.

What is the .NuGet folder in the solution for?

It allows you to configure NuGet repositories where to search packages during restore.

Should I include NuGet packages in source control?

Instead there is one in your user directory ( %USERPROFILE%\. nuget\packages on Windows, to be specific) where it puts all packages it downloads, and projects just reference these. So the simple answer these days is no, you shouldn't.

Where is the .NuGet folder?

The location of the default global packages folder. The default is %userprofile%\. nuget\packages (Windows) or ~/. nuget/packages (Mac/Linux).


1 Answers

This post is old, you should not be using solution level NuGet package restore anymore. As of version 2.7+ there is an option in the NuGet setup to automatically restore packages on build. So the .nuget folder can be deleted and the option removed from your projects.

http://docs.nuget.org/docs/reference/package-restore

UPDATE: With the release of NuGet 4.x and .NET Standard 2.0, when you use the new csproj format you can now use package references, ironically reintroducing the dependency on msbuild to restore packages, but now packages are a first class citizen of msbuild. The link above also makes mention of the PackageReference, but the following announcement details it better:

https://blog.nuget.org/20170316/NuGet-now-fully-integrated-into-MSBuild.html

And the NuGet 4.x RTM announcement, which ironically isn't as useful:

https://blog.nuget.org/20170308/Announcing-NuGet-4.0-RTM.html

UPDATE 2: Apparently with VS2017 you can even use package references with classic csproj projects, but they aren't backwards compatible anymore, and there have been some problems with restoring package sub-dependencies. I'm sure that will all be resolved.

like image 151
Jeremy Avatar answered Oct 17 '22 01:10

Jeremy