Asp.net-Core

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

  • August 27, 2021

我發現 The package:Microsoft.VisualStudio.CodeGeneration 在 nuget 中有超過 20,000,000 次下載。但我找不到任何文件。

如何使用它?

有沒有關於它的文章?

這個包有什麼作用

基本上,該包提供了一個生成程式碼的命令:

dotnet aspnet-codegenerator {name}

您可以在此處找到原始碼

使用方法

除非我們創建一個新的命令來生成程式碼,否則我們不會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.**Design**
|
|(取決於)
|-----------> 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

引用自:https://stackoverflow.com/questions/58496125