Aus*_*Dev 4 c# nuget-package .net-core
我正在构建一个 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 的副本,其中包含
<packageType name="DotnetTool" />来自https://natemcmaster.com/blog/2018/05/12/dotnet-global-tools/的建议
找到根本原因后,这个错误很搞笑,但也是系统问题的征兆。
您在输出中看到警告的这一部分了吗?
包“TestConsole 1.0.9”是使用“.NETFramework,Version=v4.6.1”而不是项目目标框架“.NETCoreApp,Version=v2.1”恢复的。此包可能与您的项目不完全兼容
这个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.
Run Code Online (Sandbox Code Playgroud)
仔细看最后几行。dotnet tool install正在尝试安装https://www.nuget.org/packages/TestConsole/。不是您本地的testconsolenuget 包!
您可以通过以下几种方式解决它:
nuget.config的是<clear/>S中的NuGet饲料所以只有./nupkg寻找到安装目录时,被用作饲料testconsole。基于 Omair 的回答,解决这个问题的实际步骤:
disable_nuget.config禁用从全局提要读取<?xml version="1.0" encoding="utf-8"?>
<configuration>
<disabledPackageSources>
<add key="nuget.org" value="true" />
</disabledPackageSources>
</configuration>
Run Code Online (Sandbox Code Playgroud)
注意:给它一个特殊的名字,这样它就不会在你不想要的时候被 nuget 无意中捡到
dotnet pack
dotnet tool install --global --configfile disable_nuget.config --add-source ./nupkg TestConsole
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3789 次 |
| 最近记录: |