gbro3n
gbro3n

Reputation: 6967

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

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

Upvotes: 5

Views: 3232

Answers (1)

itminus
itminus

Reputation: 25360

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

Upvotes: 6

Related Questions