Do you know how to manage NuGet packages with Git?
17/11/2014 12:12 PM by
Do you know the best way to manage NuGet packages with Git? You can get into all sorts of trouble by including your packages in source control.
Do not check packages into Git
The following are a few issues that are related to having your NuGet packages in source control:
- Over time the packages will grow to be too many and cloning the repository will be slow.
- You could get duplicate NuGet packages in your packages folder as new versions are updated.
- NuGet shows packages to update that have already been updated. This can happen if you have duplicate NuGet packages but they are different versions.
- It becomes harder to "clean" your solution of any unused package folders, as you need to ensure you don't delete any package folders still in use.
Nuget will automatically restore packages with out checking them in to source control
Beginning with NuGet 2.7, the NuGet Visual Studio extension integrates into Visual Studio's build events and restores missing packages when a build begins. This feature is enabled by default and packages.config will be automatically included in souce control.
On project or solution build, Visual Studio raises an event that a build is beginning within the solution.
NuGet responds to this event and checks for packages.config files included in the solution.
For each packages.config file found, its packages are enumerated and checked for existence in the solution's packages folder.
Any missing packages are downloaded from the user's configured (and enabled) package sources, respecting the order of the package sources.
As packages are downloaded, they are unzipped into the solution's packages folder.
Support in legacy versions of NuGet
It is highly recommended that you upgrade to the latest version of NuGet to to avoid having to configure your solution to not check in NuGet pagages to source control.
You can read more here http://blogs.msdn.com/b/dotnet/archive/2013/08/22/improved-package-restore.aspx?PageIndex=3#comments.
Do you feel this rule needs an update?