我正在构建一个dotnet核心工具,但无法在全球范围内安装它。我可以复制遇到的问题,但不知道如何解决。以下是我的步骤
<PackAsTool>
和<PackageOutputPath>
安装时出现以下错误
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的副本,其中包括
https://natemcmaster.com/blog/2018/05/12/dotnet-global-tools/的建议中<packageType name="DotnetTool" />
答案 0 :(得分:2)
基于Omair的答案,解决此问题的实际步骤:
disable_nuget.config
以禁止从全局供稿读取<?xml version="1.0" encoding="utf-8"?>
<configuration>
<disabledPackageSources>
<add key="nuget.org" value="true" />
</disabledPackageSources>
</configuration>
注意:给它起一个特殊的名称,这样当您不希望它被nuget意外拾取时,就不会被
dotnet pack
dotnet tool install --global --configfile disable_nuget.config --add-source ./nupkg TestConsole
答案 1 :(得分:1)
找到根本原因后,此错误很有趣,但也表明存在系统性问题。
您是否在输出中看到警告的这一部分?
使用'.NETFramework,Version = v4.6.1'而不是项目目标框架'.NETCoreApp,Version = v2.1'恢复了软件包'TestConsole 1.0.9'。该软件包可能与您的项目不完全兼容
此版本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.config
来<clear/>
的nuget提要,以便在安装./nupkg
时仅将testconsole
目录用作提要。