No executables found matching command 'dotnet-aspnet-codegenerator'" - c#
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'"
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>
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.
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"
]
}
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.
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
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
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>
After adding that I installed CodeGenerators.Mvc with nuget package manager.
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!
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.
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 ;)
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"
]
}
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>
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.
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
Start typing Environment in the windows search and you should see the Control panel option to Edit system environment variables.
Click the Environment Variables... button in the lower right corner.
Under System variables find and select the Path variable, then click Edit.
Check if the path to dotnet-aspnet-codegenerator.exe is there and if not click New and add it.
Restart your computer.
Related
NETSDK1073: The FrameworkReference 'Microsoft.AspNetCore.App' was not recognized
I use .NET Core 5.0.100-preview.7.20366.6 , Blazor webassembly, Microsoft Visual Studio Community 2019 Preview Version 16.7.0 Preview 6.0 file foo.csproj <Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>net5.0</TargetFramework> <RuntimeIdentifier>browser-wasm</RuntimeIdentifier> <UseBlazorWebAssembly>true</UseBlazorWebAssembly> </PropertyGroup> <ItemGroup> <PackageReference Include="DevExpress.Blazor" Version="20.1.5" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0-preview.7.20365.19" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.0-preview.7.20365.19" PrivateAssets="all" /> <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="5.0.0-preview.7.20365.19" /> <PackageReference Include="System.Net.Http.Json" Version="5.0.0-preview.7.20364.11" /> </ItemGroup> </Project> When press F5 to run debug: Error NETSDK1073: The FrameworkReference 'Microsoft.AspNetCore.App' was not recognized How to fix it?
For .NET Core 3.1 apps, adding <GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks> to the .csproj file will prevent this error: <PropertyGroup> <TargetFramework>netcoreapp3.1</TargetFramework> <GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks> </PropertyGroup>
I just resolved the same issue with this process: -Close the project -Delete the bin and obj folders in the Blazor.Client project -Reopen the project -Open Nuget Console: Tools -> Nuget Package Manager -> Nuget Package Manager Console -Enter dotnet restore in the command line After that I hit F5 and the project compiled, and started
Locally installing dotnet tool uses old command name
I've followed the tutorials to create a dotnet tool and install it locally. After I was satisfied, I tried changing the name of the command from botsay to something-else. Unfortunately it always installs with the command name botsay. Even if I run dotnet tool uninstall, delete the project, and start over, it keeps using the name from the tutorial. The only way I can change it is by changing the project name to something else. Why does it use the old command name and how can I change it? The directory structure is: sources --My.Project.Name ----nupkg ------My.Project.Name.1.0.0.nupkg --.config ----dotnet-tools.json My csproj is: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.1</TargetFramework> <PackAsTool>true</PackAsTool> <ToolCommandName>something-else</ToolCommandName> <PackageOutputPath>./nupkg</PackageOutputPath> </PropertyGroup> </Project> And the dotnet-tools.json is: { "version": 1, "isRoot": true, "tools": { "my-project-name": { "version": "1.0.0", "commands": [ "botsay" <--- I want this to be "something-else" ] } } }
OK, found the answer. The package was being installed from a cache. I had tried supplying the --no-cache argument to dotnet tool install, but it didn't make a difference. The solution is: run nuget locals all -List find the cached package in one of these locations delete it
Creating new blazor application throws an error when run
I am following Get started with Blazor. I have created the application and attempt to run it as is i have made no changes. There are three things in my event log. The directory specified for caching compressed content C:\inetpub\temp\IIS Temporary Compressed Files\Clr4IntegratedAppPool is invalid. Static compression is being disabled. Application 'MACHINE/WEBROOT/APPHOST/WEBAPPLICATION1' with physical root 'C:\Users\LindaL\source\repos\Daimto.RazorTest.Tools\WebApplication1\' failed to start process with commandline 'c:\program files (x86)\microsoft visual studio\2017\professional\common7\ide\extensions\microsoft\web tools\projectsystem\VSIISExeLauncher.exe -argFile "C:\Users\LindaL\AppData\Local\Temp\tmpF272.tmp"', ErrorCode = '0x80004005' : 0. Application 'MACHINE/WEBROOT/APPHOST/WEBAPPLICATION1' with physical root 'C:\Users\LindaL\source\repos\Daimto.RazorTest.Tools\WebApplication1\' failed to start process with commandline 'c:\program files (x86)\microsoft visual studio\2017\professional\common7\ide\extensions\microsoft\web tools\projectsystem\VSIISExeLauncher.exe -argFile "C:\Users\LindaL\AppData\Local\Temp\tmpF272.tmp"', ErrorCode = '0x80004005' : 0. Note i just update to visual studio professional 2017 15.9.3. I have used blazor before this was working fine. Update: This appears only in the "Blazor" project type. Update2: hitting Cntrl-F5 as opposed to just F5 – No change. Update3 Project file per request in comment in answer below <Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netstandard2.0</TargetFramework> <RunCommand>dotnet</RunCommand> <RunArguments>blazor serve</RunArguments> <LangVersion>7.3</LangVersion> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.Blazor.Browser" Version="0.6.0" /> <PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="0.6.0" PrivateAssets="all" /> <DotNetCliToolReference Include="Microsoft.AspNetCore.Blazor.Cli" Version="0.6.0" /> </ItemGroup> </Project>
Delete global.json and see if that helps. https://github.com/aspnet/Blazor/issues/1342 If that doesn't help try adding global.json with content { "sdk": { "version": "2.1.500" } } If all fails, close all Visual Studio instances and reinstall Blazor templates with dotnet new -i Microsoft.AspNetCore.Blazor.Templates and create new Blazor solution with dotnet new and use Blazor template you want.
Xunit Unit Tests will not run
I am completely stuck on this issue. So my team has a unit test project in a services test project. The tests are discovered in the test explorer pane however when I try and run the tests I get these errors: 'Multiple test adapters with the same uri 'executor://xunit/VsTestRunner2' were found. Ignoring adapter 'Xunit.Runner.VisualStudio.TestAdapter.VsTestRunner'. Please uninstall the conflicting adapter(s) to avoid this warning' '[xUnit.net 00:00:00.0251250] Skipping: (could not find dependent assembly 'Microsoft.Extensions.DependencyModel, Version=1.1.0')' 'No test is available in C:\. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.' Context information: Xunit 2.2.0 Visual Studio 15.5.2 Windows 10 1709 Build: 16299.125 My Test Projects project.json: { "version": "1.0.0-*", "testRunner": "xunit", "dependencies": { "dotnet-test-xunit": "2.2.0-preview2-build1029", "Microsoft.AspNetCore.Mvc.ViewFeatures": "1.1.3", "Microsoft.DiaSymReader": "1.0.8", "Microsoft.DiaSymReader.Native": "1.4.1", "Microsoft.Extensions.Logging.Abstractions": "1.1.2", "Microsoft.Extensions.Testing.Abstractions": "1.0.0-preview2-003121", "Newtonsoft.Json": "9.0.1", "WebServices": "1.0.0-*", "xunit": "2.2.0", "xunit.abstractions": "2.0.1", "xunit.assert": "2.2.0", "xunit.core": "2.2.0", "xunit.extensibility.core": "2.2.0", "xunit.extensibility.execution": "2.2.0", "xunit.runner.utility": "2.2.0" }, "frameworks": { "net461": { "dependencies": { "Microsoft.NETCore.Platforms": "1.1.0" } } } The Weird thing is that it works for my team members. But not me. The differences in our environments are: the latest update from Windows and Visual Studio, while they are an update or two behind. Does anyone know of a workaround?
Installing or updating "xunit.runner.visualstudio" package did the trick for me. Until that, it was not working with framework 462.
I had the same problem and I fixed it by updating Visual Studio 2017 from 15.5.2 to 15.5.4 and updating my test project references from: <ItemGroup> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170628-02" /> <PackageReference Include="xunit" Version="2.2.0" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" /> </ItemGroup> to: <ItemGroup> <PackageReference Include="xunit" Version="2.3.1" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> </ItemGroup> And restarting Visual Studio (apparently VS caches and uses the previous version even after you've updated). Not sure if one of the 3 things or the combination of them fixed it.
I encountered the same issue, but I have already had Visual Studio 2017 15.5.4 installed. In order to make it work I updated all xunit related references and now my .csproj relevant references look like this: <ItemGroup> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" /> <PackageReference Include="xunit" Version="2.3.1" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" /> </ItemGroup> Not really sure what was not working, but my advice is to make sure that these reference are within csproj and have these minimum versions.
I was having a similar issue as yours, stating could not find dependent assembly; when in fact, that assembly was there and available to the xUnit VS runner. However, what the actual issue was, I had Visual Studio set to use the 32bit test runner by default. The 'dependent assembly' it couldn't find was simply a different processor architecture than the xUnit test runner being used. To fix, as mentioned here, from the Visual Studio menu, go to Test -> Test Settings -> Default Processor Architecture and set that to X64 if you are using 64bit assemblies, or X86 if you are using 32bit assemblies. The error that the xUnit VS runner gives is very misleading to try to debug this issue. This issue I saw when installing Visual Studio on a new machine. The tests would run on my desktop maching in Visual Studio, but not on my laptop.
Close and reopen Visual Studio works for me.
If you have a project running on the same Visual Studio (or any other instance of Visual Studio), please stop it. Although I know it's awkward, it solved the problem.
If your issue in Visual Studio is that the Test Runner output seems empty, check that the relevant buttons (white boxes, below) are all selected.
I had same issue, I installed below nuget packages <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" /> <PackageReference Include="xunit" Version="2.4.1" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
Encountered this problem on VS 2019 recently. Installing VS.QualityTools.UnitTestFramework nuget fixed the issue
How to create a new dotnet core application that has both auth and EF?
I can create a new dotnetcore app that has authentication/identity using the command line: dotnet new mvc --auth Individual How can i include entity framework in the project also?
TL;DR You already have it in your project Long form answer After creating your application, it should have Entity Framework as a dependency. I'm assuming that you're running the .NET Core 2.0 SDK. Here's the output from my machine $ dotnet new mvc --auth Individual --name testForStackOverflow The template "ASP.NET Core Web App (Model-View-Controller)" was created successfully. This template contains technologies from parties other than Microsoft, see https://aka.ms/template-3pn for details. Processing post-creation actions... Running 'dotnet restore' on testForStackOverflow/testForStackOverflow.csproj... Restoring packages for testForStackOverflow/testForStackOverflow.csproj... Restore completed in 40.17 ms for testForStackOverflow/testForStackOverflow.csproj. Restore completed in 40.17 ms for testForStackOverflow/testForStackOverflow.csproj. Restore completed in 25.25 ms for testForStackOverflow/testForStackOverflow.csproj. Generating MSBuild file testForStackOverflow/obj/testForStackOverflow.csproj.nuget.g.props. Generating MSBuild file testForStackOverflow/obj/testForStackOverflow.csproj.nuget.g.targets. Restore completed in 2.84 sec for testForStackOverflow/testForStackOverflow.csproj. Restore succeeded. I then look a look at the csproj which was generated: $ cd testForStackOverflow/ ~/testForStackOverflow$ ls app.db Data Startup.cs appsettings.Development.json Extensions testForStackOverflow.csproj appsettings.json Models Views bower.json obj wwwroot bundleconfig.json Program.cs Controllers Services ~/testForStackOverflow$ cat testForStackOverflow.csproj <Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp2.0</TargetFramework> <UserSecretsId>aspnet-testForStackOverflow-AD382505-1A70-4A75-8059-1E0E3897A088</UserSecretsId> </PropertyGroup> <ItemGroup> <None Update="app.db" CopyToOutputDirectory="PreserveNewest" /> </ItemGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" PrivateAssets="All" /> <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" PrivateAssets="All" /> </ItemGroup> <ItemGroup> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" /> <DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" /> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" /> </ItemGroup> </Project> The important line of the csproj is here: <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" /> This is a reference to the ASP.NET Core metapackage. This package contains all of the common ASP.NET Core NuGet packages, including Entity Framework Core - as per this screen shot from NuGet (captured a few moments ago) This means that part of the package restore operation included restoring EF Core into your project. I would say that you should take a look at this documentation for EF Core - the link should take you directly to the section labelled "The Model". You don't need the stuff in the preceding section (labelled "Get Entity Framework Core") as you already have it. Of course, if you're using version 1.x of the .NET Core SDK, then it's a slightly different story.