No executables found matching command 'dotnet-aspnet-codegenerator'"
Solution 1
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
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
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
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
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
Darren Alfonso
Updated on July 08, 2022Comments
-
Darren Alfonso 11 months
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'"
-
nam over 6 yearsThank you for posting your solution and specifically describing variation of version # for different users etc. It saved me tons of hours.
-
CountZero about 6 yearsCurrently - Version="1.0.0"
-
Piotrek about 6 yearsThis is what I see when I try to install
CodeGeneration.Tools
to my project:Package 'Microsoft.EntityFrameworkCore.Tools.DotNet 1.0.1' has a package type 'DotnetCliTool' that is not supported by project
-
The Red Pea about 6 years@CountZero , I have ` Version="1.0.1"` how best to check the latest version number? And can I install this Reference using dotnet cli itself? When I tried
dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Tools
it created an<PackageReference>
, but I needed a<DotNetCliToolReference>
as johnnycardy answered here... One advantage ofdotnet add package
is that (it seems?) it will find and add an element with the latest version attribute, so I just manually converted from<PackageReference>
-><DotNetCliToolReference>
-
CountZero about 6 yearsLooks like 1.0.1 is the latest unless you're using a preview. nuget.org/packages/…
-
Steve Johnson almost 6 yearsWhat if this line is already there in the csproj file and we are still getting the same error? I am facing this error in VS 2017 (release and latest update installed as of date)
-
James Gould almost 6 years@SteveJohnson Rebuild the solution and it should work. If not, close and reopen the solution.
-
Lei Yang almost 6 yearsis it visual studio's bug?
-
Admin almost 6 yearsThere is no "project.json" file for the newest asp.net core version.
-
user5389726598465 over 5 years@SteveJohnson Did you ever get it to work? If so, what did you do. The line is already in csproj, and dotnet restore appears to work but when I open manage nuget packages, the CodeGeneration.Tools is still not installed.
-
Steve Johnson over 5 years@user5389726598465 Yes I did. It was because of a dependency in the project file which was not compatible with the "then version" of the .NET CORE I was using. I removed that dependency and chose the correct the preview release and it worked. Now I am on .NET CORE 2.0 and upgraded all my dependencies to .NET CORE 2.0 So i dont have the problem anymore. I am sorry I donot recall that specific incompatible dependency.
-
Steve Johnson over 5 years@user5389726598465 My current depencies look like these:
-
user5389726598465 over 5 years@SteveJohnson Thank you. Lol I figured out that that was the problem (everything is now 2.0.0), and solved the codegenerator still not being found by using the dos cmd prompt for the cmd. Details here for future readers: stackoverflow.com/questions/47765196/…
-
GazB over 5 yearsThis was the solution for me (and you're right very obvious! LOL). I was using JetBrains Rider (which has a solution and separate sub folder for project) and following instructions for vscode which doesn't. Once I jumped into the project folder not the solution it worked. Rider defaults it's Terminal to the solution. :)
-
kasif Shaikh over 4 yearspre tag is not there
-
Rob Lassche about 4 yearsAdding .dotnet/tools to my PATH in Mint 19 solved my problem.