本文介绍了如何修复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新控制台-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

安装时出现以下错误

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

安装错误

这是来自nupkg的testconsole.nuspec的副本,其中包括根据< packageType name ="DotnetTool"/> rel ="nofollow noreferrer"> 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?

此版本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工具安装正在尝试安装 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 ,该< clear/> 是nuget提要,因此仅将 ./nupkg 目录用作提要安装 testconsole 时使用feed.
  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工具安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 23:13