【问题标题】:aspnet-codegenerator: No code generators available, Even after adding Microsoft.VisualStudio.Web.CodeGeneration.Designaspnet-codegenerator:没有可用的代码生成器,即使添加了 Microsoft.VisualStudio.Web.CodeGeneration.Design
【发布时间】:2020-12-14 10:51:54
【问题描述】:

无法使用 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 core安装版本:3.1.401

操作系统:Ubuntu 20.04

【问题讨论】:

标签: asp.net-core .net-core asp.net-core-mvc razor-pages asp.net-core-razor-pages


【解决方案1】:

从 .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 Microsoft.EntityFrameworkCore.Design
  1. 将 .csproj 和 launch.json 文件中的字符串 netcoreapp3.1.4 替换为 net5.0
  2. 清除目录
    • bin
    • 对象
  3. 重建项目
  4. 最终运行:
  dotnet aspnet-codegenerator --help

如果一切正常,它将显示可用的生成器。

【讨论】:

  • 这在 web/github 的其余部分没有结果时起作用。谢谢朋友。
【解决方案2】:

这已经有几个月了,但我最近在我的所有项目中都遇到了它。

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

在终端运行:

dotnet tool uninstall --global dotnet-aspnet-codegenerator

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

【讨论】:

    【解决方案3】:

    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 上做到这一点?
    • @JonathanDaniel:据我所知,这种方法也应该适用于 MacOS。但我几乎没有使用 Apple 设备的经验。
    【解决方案4】:

    我测试你的命令,当我这样做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
    

    【讨论】:

    • 我也试过了。我猜你正在使用Windows。我已经更新了我在问题底部使用的操作系统。
    【解决方案5】:

    我找到了解决这个问题的方法:

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

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

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

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

    之后,您需要在终端上添加正确的 Web.CodeGeneration.Design 包:

    sudo apt install dotnet-sdk-3.1=3.1.301-1 dotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.3

    这对我有用!!

    【讨论】:

      猜你喜欢
      • 2020-12-06
      • 1970-01-01
      • 2015-08-05
      • 1970-01-01
      • 2016-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-08
      相关资源
      最近更新 更多