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

后端 未结 13 2251
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-15 02:16

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

相关标签:
13条回答
  • 2020-12-15 02:49
    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!

    0 讨论(0)
  • 2020-12-15 02:52

    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.

    0 讨论(0)
  • 2020-12-15 02:55

    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
    0 讨论(0)
  • 2020-12-15 02:58

    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

    0 讨论(0)
  • 2020-12-15 02:58

    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.
    0 讨论(0)
  • 2020-12-15 02:59

    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.

    0 讨论(0)
提交回复
热议问题