aspnet-codegenerator:没有可用的代码生成器,即使在添加 Microsoft.VisualStudio.Web.CodeGeneration.Design 之后

Gur*_*dhu 9 asp.net-core-mvc .net-core asp.net-core razor-pages asp.net-core-razor-pages

无法使用aspnet-codegenerator生成脚手架,下面是我尝试过的:

  1. 使用创建了一个 ASP.Net RazorPages 应用程序 dotnet new webapp

  2. 做了一个 dotnet build

  3. 安装 dotnet-aspnet-codegenerator 使用

    dotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.4

  4. dotnet aspnet-codegenerator --help

    它说:此项目中没有可用的代码生成器。将Microsoft.VisualStudio.Web.CodeGeneration.Design包作为 NuGet 包引用添加到项目中。

  5. 使用添加了步骤 4 中提到的包

    dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design

    添加的包是:

    <ItemGroup> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.4" /> </ItemGroup>

  6. 再次运行: dotnet build

    最后一步

  7. dotnet aspnet-codegenerator --help

    再次显示:此项目中没有可用的代码生成器。将 Microsoft.VisualStudio.Web.CodeGeneration.Design 包作为 NuGet 包引用添加到项目中。

.Net核心安装版本:3.1.401

操作系统:Ubuntu 20.04

小智 6

我的案例(在 MacOS 上)的解决方案是卸载并重新安装 dotnet-aspnet-codegenerator。

在终端中运行:

dotnet tool uninstall --global dotnet-aspnet-codegenerator

dotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.4
Run Code Online (Sandbox Code Playgroud)


小智 5

从 .net core 3.1.4 升级到 5.0.1 时,我遇到了同样的问题。

我的解决方案:

  1. 更新全局工具:
  dotnet tool install --global dotnet-aspnet-codegenerator
  dotnet tool update --global dotnet-aspnet-codegenerator
  dotnet tool install --global dotnet-ef
  dotnet tool update --global dotnet-ef
Run Code Online (Sandbox Code Playgroud)
  1. 添加/更新包的链接
  dotnet remove package Microsoft.VisualStudio.Web.CodeGeneration.Design
  dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
  dotnet add package Microsoft.EntityFrameworkCore.Design
Run Code Online (Sandbox Code Playgroud)
  1. 将字符串替换netcoreapp3.1.4net5.0.csproj 和 launch.json 文件
  2. 清除目录
    • 垃圾桶
    • 对象
  3. 重建项目
  4. 最后运行:
  dotnet aspnet-codegenerator --help
Run Code Online (Sandbox Code Playgroud)

如果一切正常,它将显示可用的发电机。


Yiy*_*You 0

我测试你的命令,当我这样做时dotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.4,我可以得到 在此输入图像描述

然后Ran dotnet aspnet-codegenerator --help,我收到与您相同的消息 No code generators are available in this project.Add Microsoft.VisualStudio.Web.CodeGeneration.Design package to the project as a NuGet,但是当我执行以下操作时,我可以在没有消息的情况下运行: 在此输入图像描述

我认为可能是该包没有正确添加,您可以尝试删除并重新添加。

dotnet remove package Microsoft.VisualStudio.Web.CodeGeneration.Design
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
Run Code Online (Sandbox Code Playgroud)