简体   繁体   中英

What packages are needed at a minimum for ASP.NET Core MVC (3.1)?

I created a default (template) ASP.NET Core MVC 3.1 application using Windows 10/Visual Studio 2019. (background: I am looking to re-write/convert an ASP.NET MVC 5 web site to Core 3 MVC).

After creating the default ASP.NET Core MVC solution (which I can compile/run), I noticed in NuGet, that no packages are installed by default . I have the following questions:

1) How is it that the app compiles/runs, even though no packages, not even Core MVC, are shown in Packages installed?

2) For re-writing my app/web site, I will be using MVC, Razor Views, EF Core (using SQL Server, database first approach). When searching in NuGet, there are many related Microsoft packages. What are the minimum packages I must install via NuGet (to get started)?

Have you tried looking at which SDK your project file references when you create an empty ASP.NET Core Web Application?

It's Microsoft.NET.Sdk.Web . This inherits Microsoft.AspNetCore.App , and that metapackage references a whole lot of other packages , amongst others:

  • Microsoft.AspNetCore.Mvc (>= 2.2.0 && < 2.3.0)
  • Microsoft.AspNetCore.Mvc.Razor (>= 2.2.0 && < 2.3.0)
  • Microsoft.EntityFrameworkCore (>= 2.2.6 && < 2.3.0)

So expand the SDKs node under your project, not the Packages node.

In your csproj file, you'll note at the top that the <Project> tag lists an SDK; the SDK handles inclusion of the ASP NET Core supported packages.

From ASP.NET Core Web SDK :

Features enabled by using the Web SDK:

  • Projects targeting .NET Core 3.0 or later implicitly reference:

    • The ASP.NET Core shared framework.
    • Analyzers designed for building ASP.NET Core apps.

From Microsoft.AspNetCore.App for ASP.NET Core :

Projects that target the Microsoft.NET.Sdk.Web SDK implicitly reference the Microsoft.AspNetCore.App framework.

The ASP.NET Core shared framework:

  • Doesn't include third-party dependencies.
  • Includes all supported packages by the ASP.NET Core team.

In order to get started with Entity Framework Core and SQL Server, you can install the specific provider for SQL Server -- Microsoft.EntityFrameworkCore.SqlServer should get you there and cascade the dependencies.

From Installing Entity Framework Core :

To add EF Core to an application, install the NuGet package for the database provider you want to use.

If you're building an ASP.NET Core application, you don't need to install the in-memory and SQL Server providers. Those providers are included in current versions of ASP.NET Core, alongside the EF Core runtime.

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