如何修复 NU1212 以安装 dotnet 工具 [英] How to fix NU1212 for dotnet tool install

查看:23
本文介绍了如何修复 NU1212 以安装 dotnet 工具的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个 dotnet 核心工具,但在全局安装时遇到问题.我可以复制我遇到的问题,但不知道如何解决.以下是我的步骤

I am building a dotnet core tool and I am having trouble installing it globally. I can replicate the problem I am having but don't know how to fix it. Below are my steps

  1. dotnet new console -o testconsole
  2. 修改 testconsole.csproj 以包含

testconsole.csproj

  1. dotnet restore testconsole.csproj
  2. dotnet build testconsole.csproj
  3. dotnet pack testconsole.csproj
  4. dotnet 工具安装 -g -v d --add-source ./nupkg testconsole

安装时出现以下错误

错误 NU1212:TestConsole 1.0.9 的项目包组合无效.DotnetToolReference 项目样式只能包含 DotnetTool 类型的引用

安装错误

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

Here is a copy of testconsole.nuspec from the nupkg that includes <packageType name="DotnetTool" /> per the suggestion from https://natemcmaster.com/blog/2018/05/12/dotnet-global-tools/

testconsole.nupsec

推荐答案

找到根本原因后,这​​个错误很搞笑,但也是系统问题的征兆.

After finding the root cause, this error is hilarious, but also an indication of systematic issue.

您在输出中看到警告的这一部分了吗?

Do you see this part of the warning in your output?

使用.NETFramework,Version=v4.6.1"而不是项目目标框架.NETCoreApp,Version=v2.1"恢复了包TestConsole 1.0.9".此包可能与您的项目不完全兼容

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 目录下没有类似的东西.

What is this version 1.0.9? Where is .NET Framework 4.6.1 coming from? There's nothing like that in the .NET Core SDK (I looked through the sources) or under the testconsole directory on my disk.

让我们减少日志记录的详细程度并重新运行安装命令:

Lets reduce the logging verbosity and re-run out install command:

$ 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/包/TestConsole/.不是您本地的 testconsole nuget 包!

Look at the last few lines carefully. dotnet tool install is trying to install https://www.nuget.org/packages/TestConsole/. Not your local testconsole nuget package!

您可以通过多种方式解决此问题:

You can work around it in a couple of ways:

  1. 为您的工具提供一个真正独特的名称,该名称不会与 nuget.org 或您组织的 nuget 提要中的任何内容发生冲突.
  2. 添加一个 nuget.config 是 nuget 提要,因此只有 ./nupkg 目录用作想要安装 testconsole 时的提要.
  1. Give your tools a really unique name that doesn't clash with anything on nuget.org or in your organization's nuget feed.
  2. Add a nuget.config that <clear/>s the nuget feeds so only the ./nupkg directory is used as feed when looking to install testconsole.

这篇关于如何修复 NU1212 以安装 dotnet 工具的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆