Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to target multiple frameworks in VS2017 final?

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?

like image 291
Sam Avatar asked Mar 08 '17 11:03

Sam


1 Answers

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

like image 199
Tseng Avatar answered Oct 10 '22 09:10

Tseng