NullVoxPopuli February 2016

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

Currently, I get the following error:

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.          

Here is a link to my repo: https://github.com/NullVoxPopuli/csharp-extensions
The Nuget Link: https://www.nuget.org/packages/csharp-extensions/1.2.0

In my project.json, I specify dnx46 and 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        

Answers


Matt Ward February 2016

Looking at your csharp-extensions NuGet package it looks incorrect. It has your project files and no assemblies.

I assume this was generated by running NuGet.exe package package.nuspec. This will not generate a NuGet package that can be used from NuGet.org since there are no assemblies.

If you build your .xproj in Visual Studio it will generate a .nupkg in the artifacts directory for you if you have Product outputs on build checked in the project options, which you have. Unfortunately this .nupkg file, whilst it has assemblies, only has a lib\dnxcore50 directory and NuGet will not allow you to install it into a .NET 4.6 project since NuGet finds them to be incompatible. Using the .nupkg file in the artifacts directory returns the same error. You only seem to be able to install this artifact .nupkg into a DNX project (Console or Web app) but not a DNX Class Library project.

I would take a look at existing NuGet packages and try to generate the same structure. Looking at System.Xml.XmlDocument for example has the new NuGet 3 style directory structure:

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

Only the directories above have the System.Xml.XmlDocument.dll in them.

NuGet 2 would have just the lib directory and does not support dotnet as a directory.


NullVoxPopuli February 2016

Here is the project.json configuration that eventually allowed this nuget to work with non-dnx projects:

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

the key parts were (under frameworks)

 "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-*",
            }

        },

and

using the generic test runners for xunit:

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

Post Status

Asked in February 2016
Viewed 3,393 times
Voted 12
Answered 2 times

Search




Leave an answer