如何在VS2017最终定位多个框架?

Sam*_*Sam 12 asp.net-core visual-studio-2017

对于ASP.NET Core,我可以在一个Project.json中定位多个框架(例如netcoreapp1.1dnx451):

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

在Visual Studio 2017的最终版本中,我只能定位netcoreapp1.1或者dnx451,但我认为无法同时定位两者.

我尝试直接编辑csproj文件以通过设置<TargetFramework>netcoreapp1.1;dnx451</TargetFramework>或者甚至 <TargetFrameworks>netcoreapp1.1;dnx451</TargetFrameworks>在Visual Studio中添加第二个框架而由于不支持的框架而导致错误.

那么,如何同时针对netcoreapp1.1dnx451在一个项目在Visual Studio 2017的最终版本?

Tse*_*eng 13

你需要改变一些事情.首先,<TargetFrameworks>标记是多目标的正确标记,并且;是分隔符.

在RC2的开发过程中不推荐使用DNX,因此支持DNX的最新版本是RC1.的dnxcore5x(后来dotnet5.x)绰号得到了与替代netstandard1.x(对于类库)和netcoreapp1.x应用程序.dnx4xx作为一个整体被弃用,net4xx应该被使用.

此外,当您定位.NET Framework(单独或使用.NET Core/NetStandard)时,您将需要定义运行时标识符:

<RuntimeIdentifier>win7-x86</RuntimeIdentifier>
Run Code Online (Sandbox Code Playgroud)

要么

<RuntimeIdentifier>win7-x64</RuntimeIdentifier>
Run Code Online (Sandbox Code Playgroud)

或者您想成为默认值.

更新

仅作为附加信息.当您定位多个平台时,您需要使用条件来解析包,即Condition="'$(TargetFramework)' == '<targetmoniker>'

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

否则,您可能会收到包还原错误

  • @Tseng是的,但我希望VS2017版本会修复:( (5认同)
  • 这是所有手动工作吗?没有内置工具来做到这一点? (2认同)