Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why does visual studio 2012 automatically use nuget packages in an mvc project?

I know Visual Studio 2010 a lot, and when I started using Visual Studio 2012, I noticed that it automatically uses Nuget, which I haven't used before, I only know that it's a package manager that fetches libraries from the internet. For example, when I create an empty ASP.NET MVC 4 project, the project will contain a packages.config file with 11 entries, and there will be a packages directory under the solution folder with 11 libraries.

Here are the things that I don't get.

The first may be a rhetorical question, but why? Even an empty project contains 10+ MB of packages, even if I don't use any, it seems very silly.

There is, for example, a System.Web.Mvc.dll under packages. But it is also in my GAC, it's an integral part of the .NET framework I think. Both are the exact same version (4.0.20710.0), but the files are different. Why does my project use this DLL from Nuget and not .NET/GAC? Why are the files different? If I deploy my project to an IIS server, there will also be a copy of this DLL, so having these DLL's as part of the project seems completely useless. Not to mention that it makes my deployment package bloated.

By the way bloat. There is a reference to Newtonsoft.Json.4.5.11, which is 8+ MB in itself, because it contains .NET 2, 3.5, 4, Silverlight and whatever versions of the same thing, 9 in total. When I create my project, I specify that I want to use .NET 4.5, so I'm very confused why all that stuff is on my hard drive at all.

Finally, how is this Nuget thing related to my project or solution? I cannot see the packages folder in VS, I cannot see any mention of it in the .sln file. The project does contain the file packages.config, but it's not related to the build process in any way, it seems like dead weight. I ask this because if there was some reference to Nuget, I could easily remove it, but there is no reference, so I feel confused.

like image 797
fejesjoco Avatar asked Oct 28 '13 13:10

fejesjoco


People also ask

What is NuGet package in MVC?

NuGet Packages for ASP.NET MVC UI controls. 12 Apr 20222 minutes to read. NuGet is a Package management system for Visual Studio. It makes it easy to add, update and remove external libraries in our application.

What is the significance of using NuGet packages?

NuGet provides the tools developers need for creating, publishing, and consuming packages. Most importantly, NuGet maintains a reference list of packages used in a project and the ability to restore and update those packages from that list.

Does NuGet automatically install dependencies?

By default, when installing NuGet packages, corresponding package dependencies will also be installed in your project. To avoid the installation of dependent packages, choose the Ignore Dependencies option in the Dependency behavior drop-down in NuGet Package Manager.

What is the default NuGet source?

The default is %userprofile%\. nuget\packages (Windows) or ~/. nuget/packages (Mac/Linux). A relative path can be used in project-specific nuget.


1 Answers

The first may be a rhetorical question, but why? Even an empty project contains 10+ MB of packages, even if I don't use any, it seems very silly.

I completely agree with you. The default project template is bloated with lots of crap.

That's the reason why I am always using the Empty ASP.NET application template when staring a new application. And then I enable NuGet package restore on the solution and manually install all the packages I need -> ASP.NET MVC, Razor, ...

There is, for example, a System.Web.Mvc.dll under packages. But it is also in my GAC, it's an integral part of the .NET framework I think.

No, it's not part of .NET. It's part of Visual Studio and there is also a separate install. On the server there won't be such assembly if ASP.NET MVC is not installed.

There is a reference to Newtonsoft.Json.4.5.11, which is 8+ MB in itself, because it contains .NET 2, 3.5, 4, Silverlight and whatever versions of the same thing, 9 in total. When I create my project, I specify that I want to use .NET 4.5, so I'm very confused why all that stuff is on my hard drive at all.

It's part of the NuGet package that was downloaded on your machine where the source code of your application resides, but when you publish your application only the correct version will be deployed and used.

Finally, how is this Nuget thing related to my project or solution? I cannot see the packages folder in VS, I cannot see any mention of it in the .sln file.

The NuGet source where those packages are downloaded from is configured in Tools->Library Package Manager->Package Manager Settings/Package Sources. So basic

like image 71
Darin Dimitrov Avatar answered Sep 20 '22 21:09

Darin Dimitrov