I'm trying to run dotnet aspnet-codegenerator
from my comand line. The first time I tried, I got the error No executable found matching command "dotnet-aspnet-codegenerator"
I realized I needed to install the aspnet-codegenerator
as "dotnet CLI tool" (part of their extensibility model allows adding CLI commands if I include the correct <DotNetCliToolReference>
element to the csproj file.)1
This answer tells me which <DotNetCliToolReference>
I need, i.e. <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
but it leaves me with a few questions:
- Can I install that using the command line rather than hand-editing
the csproj?
- I notice I can install packages using the command
dotnet add package
, but that adds the element<PackageReference>
and I need<DotNetCliToolReference>
; - i.e. running the command would produce this (wrong) element:
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
- I notice I can install packages using the command
- What's the difference between those two elements?
- Can I add them to the same
<ItemGroup>
? - When I have a
csproj
whose first and only<ItemGroup>
contains a<DotNetCliToolReference>
, then any subsequentdotnet add package
commands fail:error: Invalid restore input. Invalid restore input. DotnetCliToolReference-BundlerMinifier.Core Input files:
. - My workaround is to:
- remove any existing
DotNetCliToolReference
elements - run
dotnet add package
- After finished, add back what I removed.
- remove any existing
- Can I add them to the same
1 (I'm in Visual Studio Code and using the latest; so we're using csproj, not project.json)