Dotnet core PackageReference vs DotNetCliToolReference

I am trying to run dotnet aspnet-codegeneratorfrom my code string. The first time I tried, I got an errorNo executable found matching command "dotnet-aspnet-codegenerator"

I realized what I need to install aspnet-codegeneratoras a “dotnet command line tool” (part of them > the extensible model allows adding CLI commands if I include the correct element <DotNetCliToolReference>in the csproj file.) 1

This answer tells me which one <DotNetCliToolReference>I need, i.e. <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />but he leaves me some questions:

  • Can I install this using the command line and not manually? csproj?
    • I notice that I can install packages using the command dotnet add package, but this adds an item <PackageReference>, and I need to <DotNetCliToolReference>;
    • i.e. running this command will create this (wrong) element:<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
  • What is the difference between these two elements?
    • Can I add them to the same <ItemGroup>?
    • When I have the csprojfirst and only <ItemGroup>contains a <DotNetCliToolReference>, then any subsequent commands dotnet add packagewill fail: error: Invalid restore input. Invalid restore input. DotnetCliToolReference-BundlerMinifier.Core Input files:.
    • My workaround:
      • delete existing items DotNetCliToolReference
      • run dotnet add package
      • Upon completion, add back what I deleted.

1 (I'm in Visual Studio code and use the latest version, so we use csproj, not project.json)

+6
source share
1 answer
+9

All Articles