No executables found matching command 'dotnet-aspnet-codegenerator'"

C#asp.net Coreasp.net Core-Mvc.Net Core

C# Problem Overview


When trying to add a Controller in an ASP.NET Core project using Visual Studio 15 Enterprise with Update 3, I get the error below:

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

C# Solutions


Solution 1 - C#

If you're using csproj (Visual Studio 2017) instead of project.json, then you need to add the following to your csproj file:

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

Solution 2 - C#

If you are using Mac (OS X) or any supported distribution of Linux, you have to run:

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

Additionally, on Mac I added to my .zshrc (or bash equivalent)

export PATH=$HOME/.dotnet/tools:$PATH

And I had to make sure to restart Terminal.

Solution 3 - C#

For the latest version, in project.json add the following under dependencies:

"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"
}

and the following under tools:

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

Solution 4 - C#

A more robust answer than copying version numbers into your configuration file is to use NuGet to ensure that the packages are added to your project.

Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution.

First, get everything up to date. Choose the Updates tab. Check the box for Update All and run this a few times. Don't be surprised if some stuff downgrades the first couple of times you run the upgrade. Some dependencies seem to have to be handled sequentially. It took me about 5 upgrades to get everything up to date.

Then, in the browse tab, search for CodeGeneration.Tools. Install it. Do the same for CodeGenerators.Mvc. As you find additional error messages, you should be able to find any missing packages in NuGet.

Solution 5 - C#

In dotnet core 2.1.1 you'd expect that the situation has changed and you may not need to add much. I'm sorry to annoy you but the situation is same and all you need to do now is update your version of the tool or package you wish to use.

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

This worked for me. I hope it works for eveyone else that gets stuck here. Note that the key reference is DotNetCliToolReference not PackageReference

Solution 6 - C#

Add the following to your project.json:

Under dependencies:

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

Under tools:

"Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
    "version": "1.0.0-preview2-final",
    "imports": [
        "portable-net45+win8"
    ]
}
  • Version number may change depending on which version of .NET Core you're using in your project
  • You may get another error about Microsoft.DotNet.InternalAbstractions missing, in which case you'll need to get from NuGet
  • Make sure "Microsoft.VisualStudio.Web.CodeGeneration.Tools" version in dependencies matches "Microsoft.VisualStudio.Web.CodeGeneration.Tools" version in tools

Solution 7 - C#

  1. I had to add the following to my CSProj file:

<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>

  1. After adding that I installed CodeGenerators.Mvc with nuget package manager.

  2. I was still getting an error saying it can't find some file in the MCD folder so I had to copy and paste the entire bin\Debug\netcoreapp1.1 folder into bin\MCD\Debug\netcoreapp1.1

I ran the scaffolding and it worked!

Solution 8 - C#

I encountered the same issue in Visual Studio Mac Community Edition 2017. Prior to running the scaffold command from the project directory, make sure the directory has the Program.cs, Startup.cs and .csproj files. if not, then run the command ls-al and then cd into the project directory which would be inside your current project directory and then execute the scaffold command. An obvious mistake many overlook.

Solution 9 - C#

Just add tag 'DotNetCliToolReference ' and package code design on .csproj and execute code-generate command on root solution. Thats worked to me.

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

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

Command PS C:\Users\miche\projetos\asp_net_core\crud> dotnet aspnet-codegenerator controller -name ProdutosController -m Produto -dc AppDataContext --relativeFolderPath Controllers --useDefaultLayout --referenceScriptLibraries

Don't forget to build and restore solution after add package ;)

Solution 10 - C#

For VS 2015, in project.json file -

under dependencies add -

"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"

then under tools add-

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

Solution 11 - C#

In Visual Studio Code change your yourproject.csproj

<pre>
<ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.6" PrivateAssets="All" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.4" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" version= "2.1.0-preview1-final" />
    <PackageReference Include="Microsoft.Extensions.SecretManager.Tools" version= "2.0.2" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.4" />
  </ItemGroup>
  <ItemGroup>
  <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.2" />
  <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" version="2.1.0-preview1-final" />
  </ItemGroup>`enter code here`
</pre>

Solution 12 - C#

I just typed in Linux:

~/.dotnet/tools/dotnet-aspnet-codegenerator razorpage -m Movie -dc RazorPagesMovieContext -udl -outDir Pages/Movies --referenceScriptLibraries

So, I did not start with 'dotnet' (my current version: 2.2.300)

I do not like this solution, but it worked.

Solution 13 - C#

On Windows 10

In my case the installer added the wrong path to the Path environment variable.
The path added was pointing to a non existing folder under Programs. It needs to point to dotnet-aspnet-codegenerator.exe.
For me the correct path was in my user folder: ~\.dotnet\tools

You can check if the correct path was added by running: echo $env:Path
If the path is missing or incorrect you just need to add the correct path to the Path system environment variable.

You might be able to test this by using PowerShell to set your local variable: $env:Path += ";C:\Users\<YOUR_NAME_HERE>\.dotnet\tools"
But I haven't tried this.


To fix it globally

  1. Start typing Environment in the windows search and you should see the Control panel option to Edit system environment variables.
  2. Click the Environment Variables... button in the lower right corner.
  3. Under System variables find and select the Path variable, then click Edit.
  4. Check if the path to dotnet-aspnet-codegenerator.exe is there and if not click New and add it.
  5. Restart your computer.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDarren AlfonsoView Question on Stackoverflow
Solution 1 - C#johnnycardyView Answer on Stackoverflow
Solution 2 - C#PaulView Answer on Stackoverflow
Solution 3 - C#TechyView Answer on Stackoverflow
Solution 4 - C#JosiahView Answer on Stackoverflow
Solution 5 - C#Chsiom NwikeView Answer on Stackoverflow
Solution 6 - C#Darren AlfonsoView Answer on Stackoverflow
Solution 7 - C#Tyrone MoodleyView Answer on Stackoverflow
Solution 8 - C#HeikeView Answer on Stackoverflow
Solution 9 - C#Michelle RodriguesView Answer on Stackoverflow
Solution 10 - C#MayeedView Answer on Stackoverflow
Solution 11 - C#kasif ShaikhView Answer on Stackoverflow
Solution 12 - C#Rob LasscheView Answer on Stackoverflow
Solution 13 - C#Søren UllidtzView Answer on Stackoverflow