c# - 如何为 dotnet 工具安装修复 NU1212

标签 c# .net-core nuget-package

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

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

testconsole.csproj

  1. dotnet 恢复 testconsole.csproj
  2. dotnet build testconsole.csproj
  3. dotnet pack testconsole.csproj
  4. dotnet tool 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 的副本,其中包括 <packageType name="DotnetTool" />根据 https://natemcmaster.com/blog/2018/05/12/dotnet-global-tools/ 的建议

testconsole.nupsec

最佳答案

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

您是否在输出中看到这部分警告?

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 下没有类似的东西我磁盘上的目录。

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

$ 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 .

关于c# - 如何为 dotnet 工具安装修复 NU1212,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52527004/

相关文章:

c# - 使用 StructureMap 在 Model-View-Presenter 模式中进行 Presenter 注入(inject)

c# - C# 类中的绑定(bind)(映射)Json

azure - .NET Core 2.1 Azure Functions 不会在 Azure Pipelines 中构建

c# - 具有进程内托管的 Dotnet Core 多个启动类

nuget - 如何从 nuget 包中排除文件夹

visual-studio-2013 - NuGet:获取项目的所有可用更新

c# - 在窗口内绘图不会重绘和涂抹

c# - 在 Avalonedit 上为边距着色

C# 遍历 JSON 对象

asp.net-web-api - 尝试激活 'AspNetCoreRateLimit.IProcessingStrategy' 时无法解析类型 'AspNetCoreRateLimit.IpRateLimitMiddleware' 的服务