65

I would like to know

In C# or VB.NET project should we include the PACKAGE folder (nugget package folder that is created to the root of my project that contain the nupkg files and other content) to our source control repository (Git for instance).

  • Absolutely Yes, because these files are part of your code and your project won't build without them. – Sharky Aug 4 '16 at 7:16
  • I asked a similar question on SO along time ago. You can also look there for answers: stackoverflow.com/questions/1710027/… :) – cwap Mar 10 '17 at 7:49
  • I wonder why no one in Maven world ask "should we include 3rd party libs in version control". Find some solid counter-argument for NOT committing libs, though not very convincing. – Hoàng Long Apr 23 at 10:47
28

A lot of time has passed, and NuGet has changed, so here's a new answer.

NuGet no longer creates a packages folder inside your source structure. Instead there is one in your user directory (%HOME%\.nuget\packages 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. If you are worried about packages you need disappearing, you should create a local NuGet mirror that you back up separately.

  • 6
    I'm on VS2015 (consider that VS2017 has been released just 3 days before you wrote this answer), and the package folder is present in my solution root. I'm curious about how and when NuGet has changed. – Teejay May 2 '17 at 21:29
  • NuGet changed with version 3, which was released out of band sometime during the VS2015 timeframe. – Sebastian Redl May 2 '17 at 22:11
  • I just checked on my work computer and packages are where you mentioned. But on my home computer they are in the project directory. Both are on VS2015 (professional @ work, community @ home) and the home one is a very recent installation... That's strange. – Teejay May 3 '17 at 12:22
  • 6
    Just installed VS 2017 last week, created a new project yesterday and there is a package directory in my project. – Jeremy Jul 27 '17 at 17:20
  • 2
    What do you do for CI? do you make it Download all nuget packages again and again? (TBH: I, myself, am very unclear what my opinion is) – Tomer W Oct 29 '17 at 10:08
48

It depends.

Check out Bart van Ingen Schenau's answer to determine if it's possible to ignore the packages folder at all.

Basically: yes, NuGet is designed so that you can ignore the packages folder and NuGet will pull everything from the Internet if it's missing.

But should you ignore it? I say: it depends.
IMO it's a question of "can we continue working in case the package repository is not available" (be it temporarily or permanently)

For my personal OSS projects, I have the packages folder ignored in all of them.
When nuget.org is offline, I'll just wait and continue another day.

But it's something different at work.
Sure, you probably still have the packages locally on some machine, but is saving some space worth the hassle when your builds are breaking because your build server can't reach nuget.org?

We decided that space is cheap and we don't want the hassle, that's why we're committing the packages folder to source control.

  • 1
    How often is nuget.org unavailable? – Bartosz Jul 25 '18 at 8:30
  • 3
    Probably not very often. But maybe I should have said “unreachable” instead of “offline”. A few years ago, we had an incident at work where an excavator accidentally cut the internet cable to our building. Took more than a day to repair. If we had relied on nuget.org, we wouldn’t have been able to build our projects. (yes, I know, nowadays NuGet caches the packages locally...but not back then) – Christian Specht Jul 25 '18 at 15:17
28

The basic rule for what goes into a source control repository is that you store there everything related to a project that you need to be able to build, test, deploy and execute the project and which can not be generated from items already present in the repository.

In other words, if you can throw away the PACKAGE folder and its contents without affecting your ability continue working on the project (the build might take longer, but you don't have to hunt down and install anything yourself), then the folder can be safely left out of the repository.
If the folder contains 3rd-party packages that might take a long time to download or that might become unavailable, then that might be a reason to add them to your repository anyway.

  • 18
    I would add that you should keep a version of any 3rd party code used in the project stored safely, in case the 3rd party project is removed, the site hosting it is gone etc. A good place to do that is in your version control repository. That also gives you the opportunity to rollback to a previous version of that code, if needed. – Bent Nov 3 '15 at 9:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.