如何修复NU1212的dotnet工具安装

时间:2018-09-26 22:46:43

标签: c# .net-core nuget-package

我正在构建一个dotnet核心工具,但无法在全球范围内安装它。我可以复制遇到的问题,但不知道如何解决。以下是我的步骤

  1. dotnet新控制台-o testconsole
  2. 修改testconsole.csproj使其包含<PackAsTool><PackageOutputPath>

testconsole.csproj

  1. dotnet还原testconsole.csproj
  2. dotnet构建testconsole.csproj
  3. dotnet包testconsole.csproj
  4. dotnet工具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

install error

这是来自nupkg的testconsole.nuspec的副本,其中包括 https://natemcmaster.com/blog/2018/05/12/dotnet-global-tools/的建议中<packageType name="DotnetTool" />

testconsole.nupsec

2 个答案:

答案 0 :(得分:2)

基于Omair的答案,解决此问题的实际步骤:

1。创建disable_nuget.config以禁止从全局供稿读取

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <disabledPackageSources>
        <add key="nuget.org" value="true" />
    </disabledPackageSources>
</configuration>

注意:给它起一个特殊的名称,这样当您不希望它被nuget意外拾取时,就不会被

2。安装引用特殊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包!

您可以通过以下几种方法解决它:

  1. 为您的工具提供一个真正独特的名称,该名称不会与nuget.org或组织的nuget提要中的任何内容冲突。
  2. 添加一个nuget.config<clear/>的nuget提要,以便在安装./nupkg时仅将testconsole目录用作提要。
相关问题