繁体   English   中英

如何使nuget包正确地针对多个框架?

[英]How do I make a nuget package target multiple frameworks correctly?

当前,我收到以下错误:

Could not install package 'csharp-extensions 1.2.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.          

这是我的仓库的链接: https : //github.com/NullVoxPopuli/csharp-extensions
Nuget链接: https ://www.nuget.org/packages/csharp-extensions/1.2.0

在我的project.json中,我指定dnx46和dnxcore50

{
    "version": "1.2.0",
    "configurations": {
        "Debug": {
            "compilationOptions": {
                "define": [ "DEBUG", "TRACE" ]
            }
        },
        "Release": {
            "compilationOptions": {
                "define": [ "RELEASE", "TRACE" ],
                "optimize": true
            }
        }
    },
    "dependencies": {
        "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*",
        "System.Reflection": "4.1.0-*",
        "xunit": "2.1.0-*",
        "xunit.runner.dnx": "2.1.0-*"
    },
    "commands": {
        "run": "csharp_extensions",
        "test": "xunit.runner.dnx"
    },
    "frameworks": {
        "dnx46": {
            "dependencies": {
                "System.Console": "4.0.0-beta-*",
                "System.Reflection.TypeExtensions": "4.1.0-beta-*",
                "System.Runtime.Extensions": "4.0.11-beta-*",
                "System.Dynamic.Runtime": "4.0.11-beta-*",
                "Microsoft.CSharp": "4.0.1-beta-*",
                "System.IO": "4.0.11-beta-*"
            }
        },
        "dnxcore50": {
            "_": "this is the recommended windows runtime",
            "dependencies": {
                "System.Console": "4.0.0-beta-*",
                "System.Reflection.TypeExtensions": "4.1.0-beta-*",
                "System.Runtime.Extensions": "(4.0,]",
                "System.Dynamic.Runtime": "(4.0.0,]",
                "Microsoft.CSharp": "(4.0.0,]",
                "System.IO": "(4.0,]"
            }
        }
    },
}

我试图将nuget安装到的项目是一个针对.NET Framework 4.6的类库(并且不是dnx项目)

更新:

这是我用nuget pack构建nuget包时发生的情况 在此处输入图片说明

查看您的csharp-extensions NuGet软件包,它看起来不正确。 它具有您的项目文件,而没有程序集。

我假设这是通过运行NuGet.exe package package.nuspec生成的。 由于没有程序集,因此不会生成可从NuGet.org使用的NuGet程序包。

如果在Visual Studio中构建.xproj,并且在项目选项中选中了“ Product outputs on build它将在工件目录中生成.nupkg。 不幸的是,这个.nupkg文件虽然具有程序集,但只有一个lib \\ dnxcore50目录,并且NuGet不允许您将其安装到.NET 4.6项目中,因为NuGet发现它们不兼容。 在工件目录中使用.nupkg文件将返回相同的错误。 您似乎只能将此工件.nupkg安装到DNX项目(控制台或Web应用程序)中,但不能安装到DNX类库项目中。

我将看一下现有的NuGet软件包,并尝试生成相同的结构。 例如,以System.Xml.XmlDocument为例,具有新的NuGet 3样式目录结构:

\lib
    \dotnet
    \net46
\ref
    \dotnet
    \net46

仅以上目录中包含System.Xml.XmlDocument.dll。

NuGet 2将只有lib目录,不支持dotnet作为目录。

这是project.json配置,该配置最终允许此nuget与非dnx项目一起使用:

https://github.com/NullVoxPopuli/csharp-extensions/blob/2767e8ae87dcc69a14d1a33fd63b9eef364ee1ec/project.json

关键部分是(在框架下)

 "net46": {
            "frameworkAssemblies": {
                "System.Runtime": {
                    "type": "build",
                    "version": ""
                }
            },
            "dependencies": {
                "Microsoft.CSharp": "4.0.1-beta-*",
                "System.Dynamic.Runtime": "4.0.11-beta-*",
                "System.IO": "4.0.11-beta-*",
                "System.Reflection.TypeExtensions": "4.1.0-beta-*",
                "System.Runtime.Extensions": "4.0.11-beta-*",
            }

        },

对xunit使用通用测试运行程序:

"dependencies": {
    "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*",
    "System.Reflection": "4.1.0-*",
    "xunit": "2.1.0-*",
    "xunit.runners": "2.0.0",
},

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM