如何在 VS2017 final 中定位多个框架? [英] How to target multiple frameworks in VS2017 final?
问题描述
对于 ASP.NET Core,我可以在一个 Project.json 中针对多个框架(例如 netcoreapp1.1
和 dnx451
):
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.1
或 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.
我尝试通过设置 <TargetFramework>netcoreapp1.1;dnx451</TargetFramework>
甚至 <TargetFrameworks>netcoreapp1 来直接编辑 csproj 文件以添加第二个框架.1;dnx451</TargetFrameworks>
但由于框架不受支持而在 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.1
和 dnx451
?
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.
DNX 在 RC2 的开发过程中被弃用,所以支持 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屋!