What is the Microsoft ASP.NET Web Pages 2 Data Nug

2019-03-15 02:43发布

问题:

I understand that the minimum Nuget packages that I need for an ASP.NET MVC 4 Project are:

  • Microsoft ASP.NET MVC 4
  • Microsoft ASP.NET Razor 2
  • Microsoft ASP.NET Web Pages 2
  • Microsoft.Web.Infrastructure

However I am interested to know, what would the following packages add to the project?

  • Microsoft ASP.NET Web Pages 2 Data
  • Microsoft ASP.NET Web Pages 2 Web Data

i.e. What do these two packages do? The description for each of these nuget projects is the same description as Razor 2 package, which isn't too helpful.

回答1:

After doing some experimenting with MVC 4 Projects with and without the following packages

  • Microsoft ASP.NET Web Pages 2 Data
  • Microsoft ASP.NET Web Pages 2 Web Data

I have come to the conclusion that the Nuget Package description of

This package contains the runtime assemblies for ASP.NET Web Pages. ASP.NET Web Pages and the new Razor syntax provide a fast, terse, clean and lightweight way to combine server code with HTML to create dynamic web content.

is very misleading.

The Microsoft ASP.NET Web Pages 2 Data actually just contains the WebMatrix.Data.dll. This the only assembly that is added to your project when adding this package. Looking at the MSDN reference for this assembly

The WebMatrix.Data namespace contains classes that simplify database interaction in ASP.NET Web Pages. This namespace includes classes that help you to open, query, and send commands to a database, and to work with database rows that are returned by SQL queries.

And for the Microsoft ASP.NET Web Pages 2 Web Data, this package only adds the WebMatrix.DataWeb.dll (dependent on WebMatrix.Data.dll). The MSDN reference for this assembly is

The WebMatrix.WebData namespace contains classes that simplify membership and security in ASP.NET Web Pages. This namespace includes classes that help you create and delete user accounts, define roles, and manage account passwords.

So if not using WebMatrix Data to access databases and not using the simple membership provider, these packages are unnecessary.

If you are using the Simple Membership provider, or extending the Extended Membership Provider, then these packages are necessary.