Why does ASP.NET MVC 4 have so many NuGet packages and which are truly important?

前端 未结 2 1499
执念已碎
执念已碎 2020-12-23 20:21

As the title says, why do the ASP.NET MVC 4 projects have soooo many NuGet packages? Is the entire framework split into packages now? Which ones are truly important for an e

相关标签:
2条回答
  • 2020-12-23 20:41

    As the title says, why do the ASP.NET MVC 4 projects have soooo many NuGet packages?

    That's a question you need to ask the designers of the framework.

    Which ones are truly important for an empty project that will be a website, no API, etc?

    Here's the strict minimum that will allow you to configure routing and define a controller with an action rendering a Razor view:

    <packages>
      <package id="Microsoft.AspNet.Mvc" version="4.0.20710.0" targetFramework="net40" />
      <package id="Microsoft.AspNet.Razor" version="2.0.20710.0" targetFramework="net40" />
      <package id="Microsoft.AspNet.WebPages" version="2.0.20710.0" targetFramework="net40" />
      <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
    </packages>
    

    or if you prefer only 1/2 of a page:

    enter image description here

    0 讨论(0)
  • 2020-12-23 20:55

    ASP.NET MVC has been increasingly delivered via NuGet packages since ASP.NET MVC 3 Tools Update. This offers several advantages:

    • Upgrades to to components delivered via NuGet - MVC itself and other associated components (Razor, Web API) without waiting for a new "big" release of either ASP.NET MVC, .NET, or Visual Studio.
    • This also means that you can use individual parts as you'd like outside of MVC - for instance, Web API can be used outside of ASP.NET.
    • More and more, components are being shared between UI layers and other parts of ASP.NET. Some examples: routing is shared with Web Forms and Web Pages, Razor is shared with Web Pages, the new OAuth parts are shared with Web Forms.

    You'll notice that in a project from the Basic template, you'll get the following packages:

    • Microsoft.AspNet.Mvc
    • Microsoft.AspNet.Razor
    • Microsoft.AspNet.WebApi
    • Microsoft.AspNet.WebApi.Client
    • Microsoft.AspNet.WebApi.Core
    • Microsoft.AspNet.WebApi.WebHost
    • Microsoft.AspNet.WebPages
    • Microsoft.Net.Http
    • Microsoft.Web.Infrastructure
    • Newtonsoft.Json

    Five of the nine are used for Web Api, which has been highly componentized to allow developers a lot of flexibility about where and how they can use them. If you want to minimize your NuGet packages, you can use the Basic template.

    As you move up into the Basic and Internet templates, you'll see more packages to support the additional features the projects provide. Internet brings in several packages of open-source, non-Microsoft code such as OAuth and JavaScript libraries.

    There are a lot of JavaScript packages, which is a really good thing when you think about it, since this means that NuGet is automatically handling JavaScript dependencies for you - if you want to upgrade jQueryUI which in turn requires a new version of jQuery, it'll automatically upgrade jQuery for you.

    0 讨论(0)
提交回复
热议问题