DotNetCliToolReference

DotNetCliToolReference

本文介绍了dotnet核心PackageReference与DotNetCliToolReference的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从我的命令行运行 dotnet aspnet-codegenerator 。第一次尝试,出现错误找不到与命令 dotnet-aspnet-codegenerator匹配的可执行文件

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"

我意识到我需要安装 aspnet-codegenerator 作为 dotnet CLI工具(其允许添加CLI命令csproj文件的元素。)

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.)

告诉我我需要哪个< DotNetCliToolReference> ,即< DotNetCliToolReference Include = Microsoft.VisualStudio.Web.CodeGeneration。工具 Version = 1.0.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:


  1. 我可以使用命令行而不是手动编辑
    csproj来安装它吗?


    • 我注意到我可以使用命令 dotnet添加
      package
      来安装软件包。添加元素< PackageReference> ,我需要< DotNetCliToolReference>

    • 即运行命令将产生以下(错误)元素:< PackageReference Include = Microsoft.VisualStudio.Web.CodeGeneration.Tools Version = 1.0.1 />

  1. Can I install that using the command line rather than hand-editingthe csproj?
    • I notice I can install packages using the command dotnet addpackage, 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" />

  • 我可以将它们添加到相同的< ItemGroup> 吗?

  • 当我有一个 csproj 时,它的第一个也是唯一的< ItemGroup> 包含< DotNetCliToolReference> ,则任何随后的 dotnet添加程序包命令都会失败:错误:无效的还原输入。无效的还原输入。 DotnetCliToolReference-BundlerMinifier.Core输入文件:

  • 我的解决方法是:

  • Can I add them to the same <ItemGroup>?
  • When I have a csproj whose first and only <ItemGroup> contains a <DotNetCliToolReference>, then any subsequent dotnet add package commands fail: error: Invalid restore input. Invalid restore input. DotnetCliToolReference-BundlerMinifier.Core Input files:.
  • My workaround is to:

  1. 删除任何现有的 DotNetCliToolReference 元素

  2. 运行 dotnet添加软件包

  3. 完成后,添加我删除的内容。

  1. remove any existing DotNetCliToolReference elements
  2. run dotnet add package
  3. After finished, add back what I removed.


(我使用的是Visual Studio Code,并且使用的是最新版本;因此我们使用的是csproj,而不是project.json)

(I'm in Visual Studio Code and using the latest; so we're using csproj, not project.json)

推荐答案


  1. 当前添加 DotNetCliToolReference 项只能通过手动编辑csproj文件来完成,存在功能要求在

    The error you are seeing that dotnet add package fails when a DotNetCliToolReference is already present is a bug that has been fixed for the upcoming 2.0 release: https://github.com/NuGet/Home/issues/4771

    这篇关于dotnet核心PackageReference与DotNetCliToolReference的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 10:59