简体   繁体   English

.NETStandard库nuget软件包-无法安装在标准项目上

[英].NETStandard Library nuget package - cannot install on standard project

I have .NET Core project with the following project.json : 我有带有以下project.json .NET Core项目:

{
  "version": "1.0.0-*",

  "dependencies": {
    "NETStandard.Library": "1.6.0"
  },

  "frameworks": {
    "netstandard1.6": {
      "imports": "dnxcore50"
    }
  },

  "scripts": {
    "postcompile": [
      "dotnet pack --no-build --configuration %compile:Configuration%"
    ]
  }
}

I have created nuget package (see postcompile above) and published in nuget. 我创建NuGet包(见postcompile以上)和出版的NuGet。

Then I've created standard 4.6.2 library, but cannot install package - there is error that package doesn't contain valid assemblies for target .NET Framework 4.6.2. 然后,我创建了标准的4.6.2库,但是无法安装软件包-软件包不包含目标.NET Framework 4.6.2的有效程序集的错误。

How should I prepare nuget package to make it available in standard library? 我应该如何准备nuget软件包以使其在标准库中可用? I thiough that target NETStandard is valid for both - core and standard projects. 尽管目标NETStandard对核心项目和标准项目均有效。

If you check the compatibility matrix for .Net Standard it looks like .Net 4.6.2 only supports NetStandard 1.5. 如果检查.Net Standard的兼容性矩阵,则看起来.Net 4.6.2仅支持NetStandard 1.5。 Under frameworks you are targeting 1.6 that is marked for vNext. 在框架下,您将目标标记为vNext的1.6。

See here for the compatibility matrix to know what version you should target 有关兼容性矩阵,请参见此处,以了解您应该定位的版本

So in other words if you change your config to the following you should be able to reference the library freely: 因此,换句话说,如果将配置更改为以下内容,则应该可以自由引用该库:

"frameworks": 
{
    "netstandard1.5": {}
}

You don't need to add another framework type like suggested in another answer since 4.6.2 should be able to reference a 1.5 Standard. 您无需添加其他答案中建议的其他框架类型,因为4.6.2应该能够引用1.5标准。

you should be able to add support for .Net Framework 4.6.2 with adding "net462" to your project.json: 您应该能够通过在project.json中添加“ net462”来添加对.Net Framework 4.6.2的支持:

{
  "version": "1.0.0-*",

  "dependencies": {
    "NETStandard.Library": "1.6.0"
  },

  "frameworks": {
    "netstandard1.6": {
      "imports": "dnxcore50"
    },
    "net462": {
        "dependencies" : {
            "System.Runtime": "4.0.20.0" // you may have to add this
            // add here your dependencies
        }
    }
  },

  "scripts": {
    "postcompile": [
      "dotnet pack --no-build --configuration %compile:Configuration%"
    ]
  }
}

see also my project.json on github with a few supported frameworks 另请参阅我在github上的project.json和一些受支持的框架

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将NuGet软件包安装到项目中 - cannot install NuGet package into project 每当我在NetStandard Library Project中使用Nuget包时,是否都必须将DLL从Nuget包复制到输出目录中? - Do I have to copy the DLLs from the Nuget Package to the output directory everytime I use the Nuget Package in NetStandard Library Project 在不同的 netstandard2.0 库 NU1202 中安装 netstandard2.0 Nuget 包 - Installing a netstandard2.0 Nuget Package inside a different netstandard2.0 library NU1202 有什么方法可以使用 .netstandard2.0 或 .netstandard3.0 将 .NETFramework 4.7.1 nuget 安装到项目中 - Is there any way we can install .NETFramework 4.7.1 nuget into project using .netstandard2.0 or .netstandard3.0 如何创建.netstandard nuget包? - How to create .netstandard nuget package? 无法安装nuget package unity 2 - Cannot install nuget package unity 2 无法在.NET标准库项目中从NuGet安装log4net - Failed to install log4net from NuGet in a .NET Standard library project 无法安装 nuget 包 - 未找到包错误 - Cannot install nuget package - package not found error 如何在Mono项目中安装4.5.2 nuget包? - How to install 4.5.2 nuget package in Mono project? 创建依赖于 netstandard 包的 netcore 3.0 项目的 NuGet 包 - Create a NuGet package of a netcore 3.0 project which is dependent upon netstandard packages
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM