13

For ASP.NET Core I could target multiple frameworks (for example netcoreapp1.1 and dnx451) in one Project.json:

"frameworks": {
   "netcoreapp1.1": {
     "dependencies": {
       "Microsoft.NETCore.App": {
         "version": "1.1.0",
         "type": "platform"
       }
     },
     "imports": [
       "dotnet5.6",
       "portable-net45+win8"
     ]
   },
   "dnx451": {}
 },

In the final Version of Visual Studio 2017 I can only target either netcoreapp1.1 or dnx451, but I see no way to target both.

I tried editing the csproj-file directly to add a 2nd Framework by Setting either <TargetFramework>netcoreapp1.1;dnx451</TargetFramework> or even <TargetFrameworks>netcoreapp1.1;dnx451</TargetFrameworks> but get Errors in Visual Studio due to unsupported frameworks.

So how Do I target both netcoreapp1.1 and dnx451 in one project in the final version of Visual Studio 2017?

Tseng
  • 61,549
  • 15
  • 193
  • 205
Sam
  • 28,421
  • 49
  • 167
  • 247
  • Have you tried adding a second `TargetFramework` element? So `netcoreapp1.1net462`? – DavidG Mar 08 '17 at 11:33
  • dnx is a deprecated moniker (it was deprecated when RC2 came) iirc as RC1 was the last release which supported DNX. RC2 and upwards only run with the new dotnet tooling. You should use `netxxx` instead – Tseng Mar 08 '17 at 11:52
  • I found this issue to provide more detail on the answer: https://stackoverflow.com/questions/42747977/how-do-you-multi-target-a-net-core-class-library-with-csproj – crimbo Oct 02 '17 at 23:23

1 Answers1

13

There will be a few things you need to change. First the <TargetFrameworks> tag is the correct one for multi targeting and ; is the separator.

DNX was deprecated during development of RC2, so last version which supported DNX was RC1. The dnxcore5x (and later dotnet5.x) moniker got replaced with netstandard1.x (for Class libraries) and netcoreapp1.x for applications. dnx4xx got deprecated as a whole and net4xx should be used.

Additionally, when you target .NET Framework (alone or with .NET Core/NetStandard), you will need to define a runtime identifier:

<RuntimeIdentifier>win7-x86</RuntimeIdentifier>

or

<RuntimeIdentifier>win7-x64</RuntimeIdentifier>

Or whichever you want to be the default.

Update

Just as an additional information. When you target more than one platform, you need to use conditionals for package resolution, i.e. Condition="'$(TargetFramework)' == '<targetmoniker>'

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp1.1'">
    <PackageReference Include="Microsoft.NETCore.App">
      <Version>1.0.1</Version>
    </PackageReference>
</ItemGroup>

Otherwise you may get package restore errors

Community
  • 1
  • 1
Tseng
  • 61,549
  • 15
  • 193
  • 205
  • So correct would be for example `netstandard1.6;net462` for a class library? – Sam Mar 08 '17 at 13:38
  • 1
    Yeah. But a common workaround for EF Core Tools was to set class library also to `netcoreapp1.x` because otherwise the tools wouldn't find the DbContext which is outside of the ASP.NET Core application (common practice to put DbContext in a class library). Dunno if this was fixed in the new tooling, but it was a limitation on VS2015 with project.json and the .NET Core Tools for VS, see https://learn.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet#preview-2-known-issues – Tseng Mar 08 '17 at 13:43
  • @Dismissile: So far yea. But there was no UI for most of the project.json settings neither – Tseng Mar 08 '17 at 17:16
  • 5
    @Tseng true, but I was hoping that would be fixed by the VS2017 release :( – Dismissile Mar 08 '17 at 17:21