如何在VS2017 Final中针对多个框架? [英] How to target multiple frameworks in VS2017 final?

查看:116
本文介绍了如何在VS2017 Final中针对多个框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

在Visual Studio 2017的最终版本中,我只能定位netcoreapp1.1dnx451,但我看不到同时定位这两个目标的方法.

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.

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

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.

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

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

推荐答案

您需要更改一些内容.首先,<TargetFrameworks>标签是用于多目标的正确标签,而;是分隔符.

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.

在RC2的开发过程中不推荐使用DNX,因此支持DNX的最新版本是RC1. dnxcore5x(以及后来的dotnet5.x)绰号被netstandard1.x(对于类库)和netcoreapp1.x代替. dnx4xx整体已弃用,应使用net4xx.

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.

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

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

<RuntimeIdentifier>win7-x86</RuntimeIdentifier>

<RuntimeIdentifier>win7-x64</RuntimeIdentifier>

或者您想成为默认值的任何人.

Or whichever you want to be the default.

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

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

这篇关于如何在VS2017 Final中针对多个框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆