简体   繁体   中英

Why does NuGet put packages at the “solution level”?

When you add a nuget package to a project it puts the assemblies in a /packages folder at the solution level.

I know that there are ways to change this, but I'm wondering why this is the default location, as it seems very unhelpful for these reasons:

1) If you have a project that is part of multiple solutions, the /packages folder won't necessarily be where you the project expects it.

2) You are expected to manually check it into source control for other team members, which is much less convenient than if it was part of the project that needs it.

3) If you move the project somewhere else on the file system or to a different machine that doesn't have the full code base, it won't find the /packages folder where it expects to.

It seems all of these would be resolved if NuGet just used a /packages folder inside the project, not the solution. And that seems like a much more logical place to put packages that the project relies on anyway.

So... I'm assuming that there were/are some good reasons for doing it at the solution level, and I'm hoping someone can enlighten me.

You should have a read at this, that explains how to use nuget without commiting packages to your source control, and by side effect solve points 1 and 3 of your question: http://blog.davidebbo.com/2011/03/using-nuget-without-committing-packages.html

I think it's to save disk space. If you had a large solution with 50 projects and you used a package in every one of those, you would end up with 50 copies of that package, binaries and all. Whereas keeping them at solution level is far more efficient in that respect.

In terms of source control, you shouldn't be putting your actual packages folder in there. Just add the packages.config file and either do what David Ebbo suggests in the blog post mentioned by mathieu or create a simple batch file to download all your packages based on the packages.config files it can find.

It's not much effort to create your own company nuget feed, so you can keep your private packages in there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM