简体   繁体   中英

.NETStandard Library nuget package - cannot install on standard project

I have .NET Core project with the following project.json :

{
  "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.

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.

How should I prepare nuget package to make it available in standard library? I thiough that target NETStandard is valid for both - core and standard projects.

If you check the compatibility matrix for .Net Standard it looks like .Net 4.6.2 only supports NetStandard 1.5. Under frameworks you are targeting 1.6 that is marked for vNext.

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.

you should be able to add support for .Net Framework 4.6.2 with adding "net462" to your project.json:

{
  "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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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