首页 文章

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

提问于
浏览
12

对于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": {}
 },

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

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

那么如何在Visual Studio 2017的最终版本中的一个项目中同时定位 netcoreapp1.1dnx451

1 回答

  • 13

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

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

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

    <RuntimeIdentifier>win7-x86</RuntimeIdentifier>
    

    要么

    <RuntimeIdentifier>win7-x64</RuntimeIdentifier>
    

    或者您想成为默认值 .

    更新

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

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

    否则,您可能会收到包恢复错误

相关问题