Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In ASP.NET MVC Core, what do the Microsoft.AspNetCore.Razor.Design and Microsoft.VisualStudio.Web.CodeGeneration.Design packages do?

Tags:

asp.net-core

Are they only needed at design time? Can they be removed without causing any build issues? (Targeting framework netcoreapp2.1).

like image 614
gb2d Avatar asked Oct 23 '18 12:10

gb2d


People also ask

What is Microsoft ASP.NET Core razor design?

AspNetCore. Razor. Design contains MSBuild support for Razor. If you're developing an asp.net core app, there's no need to add an package reference on Microsoft.

What is razor pages in ASP.NET Core MVC?

Razor Pages is a newer, simplified web application programming model. It removes much of the ceremony of ASP.NET MVC by adopting a file-based routing approach. Each Razor Pages file found under the Pages directory equates to an endpoint.

What is razor in ASP.NET MVC?

Razor is a markup syntax that lets you embed server-based code into web pages using C# and VB.Net. It is not a programming language. It is a server side markup language. Razor has no ties to ASP.NET MVC because Razor is a general-purpose templating engine. You can use it anywhere to generate output like HTML.

What is razor view in ASP.NET Core?

Razor markup is code that interacts with HTML markup to produce a webpage that's sent to the client. In ASP.NET Core MVC, views are .cshtml files that use the C# programming language in Razor markup. Usually, view files are grouped into folders named for each of the app's controllers.


1 Answers

The package of Microsoft.AspNetCore.Razor.Design contains MSBuild support for Razor. If you're developing an asp.net core app, there's no need to add an package reference on Microsoft.AspNetCore.Razor.Design manually (and also you're not supposed to remove them manually). Because it is referenced by Microsoft.AspNetCore.App meta package, which means if you have a dependency on Microsoft.AspNetCore.App, you'll reference the package automatically.

The package of Microsoft.VisualStudio.Web.CodeGeneration.Design is a quite different one. As the name suggests, it is used to generate codes only. For example, you want to develop a project without Visual Studio:

  1. You create a new project using the command of dotnet new mvc
  2. And then you create a new Model named App.Models.MyModel mannually
  3. Typically, we'll use Visual Studio to generate controllers, views, DbContext and so on. But what if we don't have Visual Studio?

If we have the Microsoft.VisualStudio.Web.CodeGeneration.Design referenced in our *.csproj file, we can create the CRUD scaffold using the following command :

dotnet aspnet-codegenerator controller -m $model -dc $dcClass -name $controllerName -namespace $controllerNamespace -outDir Controllers --useDefaultLayout

There're also some other sub commands such as :

dotnet aspnet-codegenerator identity -dc $dcClass

However, this package is only used to scaffold. Once you have the codes generated, you can feel free to remove this package before publish.

As a side note, to use the dotnet aspnet-codegenerator command, we should first install the tool:

dotnet tool install --global dotnet-aspnet-codegenerator
like image 136
itminus Avatar answered Oct 04 '22 21:10

itminus