Reference a .NET Core Library in a .NET 4.6 project

后端 未结 5 1089
夕颜
夕颜 2020-11-30 00:11

Maybe I have a miss understanding of what \".NET Core Library\" means, but when I try to add a .NET Core Library in a .NET 4.6 Assembly using Visual Studio 2015, I get the e

5条回答
  •  萌比男神i
    2020-11-30 01:14

    This can now be done with .Net Core RC2. Here is how:

    1. Ensure your .Net RC2 projects' project.json is configured to include the relevant .net framework. For example this section references .Net 4.51 which can be reference by any of the frameworks equal or above this version:

    Example:

    "frameworks": {
      "net451": { },
      "netstandard1.5": {
      "dependencies": {
        "NETStandard.Library": "1.5.0-rc2-24027"
      },
      "imports": [
        "portable-net45+wp80+win8+wpa81+dnxcore50",
        "portable-net451+win8"
      ]
     }
    },
    
    1. Package your RC2 application as a Nuget package. I haven't seen how to do this from Visual Studio yet, but it can be done from the command line with:

      dotnet pack -o e:\packages

    If you want to update it on every build you can add the following to the project.json file which updates the package automatically into a parent directory.:

    "scripts": {
      "postcompile": [
        "dotnet pack --no-build --configuration Debug -o ..//..//..//packages"
    ]}
    
    1. Add the Nuget package into your .net 4.6 application. This can be done several ways. A simple way is to add the location you saved the package to as a packaage source reference.

    2. Increment the version number in the project.json file each time you build to ensure your other applications see the update.

提交回复
热议问题