如何使用 Microsoft.VisualStudio.Web.CodeGeneration?

久违的*_*恐惧感 7 asp.net-core

我发现包:Microsoft.VisualStudio.CodeGeneration 在 nuget 中有超过 20,000,000 次下载。但我找不到任何文档。

如何使用它?

有没有关于它的文章?

itm*_*nus 10

这个包有什么作用

基本上,该软件包提供了一个生成代码的命令:

dotnet aspnet-codegenerator {name}
Run Code Online (Sandbox Code Playgroud)

您可以在此处找到源代码

包的使用方法

我们不Microsoft.VisualStudio.Web.CodeGeneration 直接使用 ,除非我们正在创建一个新命令来生成代码。

因为它是一个通用的命令库,所以在其他包中定义了具体的命令。例如,该dotnet aspnet-codegenerator controller命令在Microsoft.VisualStudio.Web.CodeGenerators.Mvc 中定义。并且命令dotnet aspnet-codegenerator identity也在CG.MVC包中定义。

通常,由于这个包是一个通用库,你不会直接引用这个包。相反,您将添加包Microsoft.VisualStudio.Web.CodeGeneration.Design。请注意,该Microsoft.VisualStudio.Web.CodeGeneration.Design包依赖于Microsoft.VisualStudio.Web.CodeGenerators.Mvc,并且Microsoft.VisualStudio.Web.CodeGenerators.Mvc依赖于Microsoft.VisualStudio.Web.CodeGeneration

Microsoft.VisualStudio.Web.CodeGeneration。设计
   | 
   |(取决于)
   |-----------> Microsoft.VisualStudio.Web.CodeGenerators。MVC
                | 
                |(取决于)
                |-----------> Microsoft.VisualStudio.Web.CodeGeneration

请注意,当您使用 Visual Studio构建控制器/标识时,Microsoft.VisualStudio.Web.CodeGeneration.Design它会自动添加到您的依赖项中。

如果您使用的是 VSCode/CLI,则需要手动添加此类包引用。请参阅https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-mvc-app/adding-model?view=aspnetcore-3.0&tabs=visual-studio-code#add-nuget-packages