Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use Microsoft.VisualStudio.Web.CodeGeneration?

Tags:

asp.net-core

I find that The package:Microsoft.VisualStudio.CodeGeneration has over 20,000,000 downloads in the nuget.but I can not find any doc.

how to use it?

any articles about it?

like image 405
user666 Avatar asked Oct 22 '19 01:10

user666


1 Answers

What does this package do

Basically, the package offers a single command to generate code:

dotnet aspnet-codegenerator {name}

You can find the source code here.

How to use the package

We don't use the Microsoft.VisualStudio.Web.CodeGeneration directly unless we're creating a new command to generate code.

Because it is a command library for generic purpose, concrete commands are defined in other packages. For example, the dotnet aspnet-codegenerator controller command is defined in Microsoft.VisualStudio.Web.CodeGenerators.Mvc. And the command dotnet aspnet-codegenerator identity is also defined in the CG.MVC package.

Usually , since this package is a generic purpose library, you won't reference this package directly. Instead, You'll add the package Microsoft.VisualStudio.Web.CodeGeneration.Design. Be aware the Microsoft.VisualStudio.Web.CodeGeneration.Design package has a dependency on Microsoft.VisualStudio.Web.CodeGenerators.Mvc, and the Microsoft.VisualStudio.Web.CodeGenerators.Mvc depends on Microsoft.VisualStudio.Web.CodeGeneration:

Microsoft.VisualStudio.Web.CodeGeneration.Design
   | 
   |(depends on)
   |-----------> Microsoft.VisualStudio.Web.CodeGenerators.Mvc
                | 
                |(depends on)
                |-----------> Microsoft.VisualStudio.Web.CodeGeneration

Be aware the Microsoft.VisualStudio.Web.CodeGeneration.Design is automatically added into your dependencies when you use Visual Studio to scaffold a controller/identity.

If you're using a VSCode/CLI, you need to manually add such a package reference. See https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/adding-model?view=aspnetcore-3.0&tabs=visual-studio-code#add-nuget-packages

like image 112
itminus Avatar answered Oct 22 '22 18:10

itminus