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

问题描述

我无法尝试使用 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

解决方法

此问题的根本原因已在 this issue 中描述为 .NET 代码期望不区分大小写的文件系统在 Linux 主机上失败。

suggested workaround 将临时挂载您在 vfat 文件系统上的 ~/.nuget 目录。

为此创建一个包含文件系统的虚拟文件

dd if=/dev/zero of=/tmp/mynuget bs=1024k count=2000
mkfs.vfat /tmp/mynuget

然后挂载

sudo mount -o uid=myuser,gid=myuser -t vfat /tmp/mynuget /home/myuser/.nuget

并使用它

dotnet restore
dotnet aspnet-codegenerator ...
,

这已经有几个月的历史了,但是最近我所有的项目都碰到了它。

如果其他人登陆此页面,在我的案例中(MAC OS),解决方案是卸载并重新安装dotnet-aspnet-codegenerator。

在终端中运行:

dotnet tool uninstall --global dotnet-aspnet-codegenerator

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

我测试了您的命令,当我执行dotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.4时,我可以得到 enter image description here

然后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, 但是当我执行以下操作时,我可以在不显示消息的情况下运行: enter image description here

我认为该软件包未正确添加,您可以尝试删除并重新添加。

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

我找到了此问题的解决方案:

最新版本存在一些问题,因此您必须通过在终端上编写以下命令,将sdk的版本降级为3.1.3 :

sudo apt install dotnet-sdk-3.1 = 3.1.301-1

之后,您需要安装以下内容:

dotnet工具安装--global dotnet-aspnet-codegenerator --version 3.1.3

之后,您需要通过在终端上编写以下代码来添加正确的Web.CodeGeneration.Design程序包:

sudo apt安装dotnet-sdk-3.1 = 3.1.301-1 dotnet工具安装--global dotnet-aspnet-codegenerator --version 3.1.3

那对我有用!

,

从.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
  1. 添加/更新软件包的链接
  dotnet remove package Microsoft.VisualStudio.Web.CodeGeneration.Design
  dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design
  dotnet add package Add package Microsoft.EntityFrameworkCore.Design
  1. 将.csproj和launch.json文件中的字符串netcoreapp3.1.4替换为net5.0
  2. 清除目录
    • bin
    • obj
  3. 重建项目
  4. 最后运行:
  dotnet aspnet-codegenerator --help

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...