Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
600 views
in Technique[技术] by (71.8m points)

asp.net core - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...