找不到与命令“dotnet-aspnet-codegenerator”匹配的可执行文件

当尝试使用Visual Studio 15 Enterprise with Update 3在ASP.NET Core项目中添加Controller时,出现以下错误:

"The was an error running the selected code generator: No executables found matching command 'dotnet-aspnet-codegenerator'"

如果您使用的是csproj(Visual Studio 2017)而不是project.json,那么您需要将以下内容添加到您的csproj文件中:

  <ItemGroup> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" /> </ItemGroup> 

对于最新版本,在project.json中添加下面的依赖关系:

 "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { "version": "1.1.0-preview4-final", "type": "build" }, "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": { "type": "build", "version": "1.1.0-preview4-final" } 

和下面的工具:

 "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { "version": "1.1.0-preview4-final", "imports": [ "portable-net45+win8" ] } 

将版本号复制到configuration文件中的更健壮的答案是使用NuGet来确保将包添加到您的项目中。

工具 – > NuGet包pipe理器 – >pipe理解决scheme的NuGet包。

首先,让所有的东西都是最新的。 select更新选项卡。 选中“更新全部”checkbox并运行几次。 如果某些东西在升级前几次降级,请不要感到惊讶。 一些依赖似乎必须按顺序处理。 我花了大约5次升级,以获得一切更新。

然后,在浏览选项卡中searchCodeGeneration.Tools 。 安装它。 对CodeGenerators.Mvc执行相同的操作。 当您发现其他错误消息时,您应该能够在NuGet中find任何缺失的软件包。

将以下内容添加到您的project.json中:

在依赖项下:

 "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": { "version": "1.0.0-preview2-final", "type": "build" } 

在工具下:

 "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { "version": "1.0.0-preview2-final", "imports": [ "portable-net45+win8" ] } 
  • 版本号可能会有所不同,具体取决于您在项目中使用的.NET Core版本
  • 您可能会得到另一个有关Microsoft.DotNet.InternalAbstractions错误,在这种情况下,你需要从NuGet
  • 确保依赖关系中的“Microsoft.VisualStudio.Web.CodeGeneration.Tools”版本与工具中的“Microsoft.VisualStudio.Web.CodeGeneration.Tools”版本匹配
  1. 我不得不将以下内容添加到我的CSProj文件中:
 <ItemGroup> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0-msbuild3-final" /> <DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="1.0.0-msbuild3-final" /> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0-msbuild3-final" /> </ItemGroup> 

对于VS 2015,在project.json文件中 –

在依赖项下添加 –

 "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { "version": "1.0.0-preview2-final", "imports": [ "portable-net45+win8" ] }, "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": "1.0.0-preview2-final" 

然后在工具add-

 "Microsoft.VisualStudio.Web.CodeGeneration.Tools": { "version": "1.0.0-preview2-final", "imports": [ "portable-net45+win8" ] }