问题描述
我正在尝试从我的命令行运行 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:
- 我可以使用命令行而不是手动编辑
csproj来安装它吗?
- 我注意到我可以使用命令
dotnet添加
来安装软件包。添加元素
package< PackageReference>
,我需要< DotNetCliToolReference>
; - 即运行命令将产生以下(错误)元素:
< PackageReference Include = Microsoft.VisualStudio.Web.CodeGeneration.Tools Version = 1.0.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" />
- I notice I can install packages using the command
- 我可以将它们添加到相同的
< 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 subsequentdotnet add package
commands fail:error: Invalid restore input. Invalid restore input. DotnetCliToolReference-BundlerMinifier.Core Input files:
. - My workaround is to:
- 删除任何现有的
DotNetCliToolReference
元素 - 运行
dotnet添加软件包
- 完成后,添加我删除的内容。
- remove any existing
DotNetCliToolReference
elements - run
dotnet add package
- 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)
推荐答案
-
当前添加
DotNetCliToolReference
项只能通过手动编辑csproj文件来完成,存在功能要求在The error you are seeing that
dotnet add package
fails when aDotNetCliToolReference
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!