Creating a .NET Core Console Application supporting multiple frameworks

Yesterday, I had to implement in a .NET Core Console Application a non-ASP.NET Core portable class library. With .NET Core, this manipulation is easy. Indeed, you have just to add a reference to the correct framework in your appliation's project json file, and all will work fine.

This is my project.json before any modification (you can note this is the default project.json file) :

To know which framework you have to target, look in the properties of the portable class library (you can see here I have to target the .NET Framework 4.5) :

To target the .NET Framework 4.5 in your .NET Core Console Application, you have just to adjust the frameworks you address to in the "frameworks" section in your project.json file. After the modification, it will be looks like this :

You can see here I'm still targeting the .NET Core 1.0.1 framework, but I also reference the .NET 4.5 portable framework, which allows me to reference the two .NET 4.5 portable class libraries I needed to use, libvideo and ClassLibrary2.

I needed here to include the portable 4.5 .NET framework but I also could add any other .NET framework, like .NET Framework 4.5.2 for example.


{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
  },

  "frameworks": {
    "net452": {
    },
    "netcoreapp1.0": {
      "imports": "dnxcore50",
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.1"
        }
      }
    },
    "dotnet": {
      "imports": "portable-net45",
      "dependencies": {
        "ClassLibrary2": {
          "target": "project"
        },
        "libvideo": {
          "target": "project"
        }
      }
    }
  }
}

With this project.json, you can see my console application has the 3 frameworks :

19/11/2016
  • dotnet
  • .NET frameworks
  • .NET Core