Search code examples
c#asp.netportable-class-library.net-core.net-core-rc2

Nuget package with NET Standard 1.X


As a proof-of-concept, I would like to create a Nuget package that consists of a single assembly. This assembly is compiled using the brand new .NET Standard 1.X profile. My idea is to make it usable not only by .NET Core, but also from .NET 4.6.1 (full framework), or even older versions, but I don't know how.

For the moment, I created a nuspec file that looks like this:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>

    <id>MyPackage</id>
    <description>MyPackage</description>

    <version>X.X.X.X</version>
    <authors>JMN</authors>
    <owners>JMN</owners>
    <licenseUrl>http://opensource.org/licenses/Apache-2.0</licenseUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>

  </metadata>

  <files>
    <file src="bin\Release\MyLib.dll" target="lib\netstandard1.X\MyLib.dll" />
  </files>

</package>

The problem is that, when adding the package to a project that targets .NET Framework 4.6.1, it says this message (output window)

Could not install package 'MyLib X.X.X.X'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6.1', 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.

What should I do to make my nuget package usable for both Frameworks (at least both .NET Standard 1.X and .NET Framework 4.6.1).


Solution

  • You don't need your own nuspec at all.

    Simply create an RC 2 project.json and then use dotnet pack to generate a NuGet package.

    http://dotnet.github.io/docs/core-concepts/libraries/libraries-with-cli.html

    You cannot expect older versions of .NET Framework to support such package, as .NET Standard 1.5 is too high a version.