我正在构建一个 dotnet 核心工具,但我在全局安装时遇到了问题。我可以复制我遇到的问题,但不知道如何解决。以下是我的步骤
- dotnet 新控制台 -o 测试控制台
- 修改 testconsole.csproj 以包含
<PackAsTool>
和<PackageOutputPath>
- dotnet 恢复 testconsole.csproj
- dotnet build testconsole.csproj
- dotnet pack testconsole.csproj
- dotnet tool install -g -v d --add-source ./nupkg testconsole
安装时出现以下错误
error NU1212: Invalid project-package combination for TestConsole 1.0.9. DotnetToolReference project style can only contain references of the DotnetTool type
这是来自 nupkg 的 testconsole.nuspec 的副本,其中包括
<packageType name="DotnetTool" />
根据 https://natemcmaster.com/blog/2018/05/12/dotnet-global-tools/ 的建议
最佳答案
找到根本原因后,这个错误很搞笑,但也是系统问题的迹象。
您是否在输出中看到这部分警告?
Package 'TestConsole 1.0.9' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETCoreApp,Version=v2.1'. This package may not be fully compatible with your project
1.0.9 是什么版本? .NET Framework 4.6.1 来自哪里?在 .NET Core SDK(我查看了源代码)或 testconsole
下没有类似的东西我磁盘上的目录。
让我们减少日志记录的详细程度并重新运行安装命令:
$ dotnet tool install -g -v n --add-source ./nupkg testconsole
Build started 2018-09-26 7:16:47 p.m..
1>Project "/tmp/q2whkgqf.tbt/restore.csproj" on node 1 (Restore target(s)).
1>Restore:
Restoring packages for /tmp/q2whkgqf.tbt/restore.csproj...
CACHE https://api.nuget.org/v3-flatcontainer/testconsole/index.json
CACHE https://api.nuget.org/v3-flatcontainer/testconsole/1.0.9/testconsole.1.0.9.nupkg
Installing TestConsole 1.0.9.0.
仔细看最后几行。 dotnet tool install
正在尝试安装 https://www.nuget.org/packages/TestConsole/ .不是你本地的testconsole
nuget 包!
您可以通过多种方式解决它:
- 为您的工具起一个真正独特的名称,该名称不会与 nuget.org 上或您组织的 nuget 源中的任何内容冲突。
- 添加
nuget.config
那<clear/>
是 nuget 提要,所以只有./nupkg
寻找安装时目录用作提要testconsole
.
关于c# - 如何为 dotnet 工具安装修复 NU1212,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52527004/