0

我在源代码中使用预处理器条件来根据 RuntimeIdentifier 发出不同的代码。但是,由于我无法选择同时基于 TargetFramework 和 RuntimeIdentifier 的上下文,因此代码始终显示为灰色。

在 Visual Studio 导航栏中,我可以在 net461 和 netstandard2.0 之间切换。如何在 TargetFramework 和 RuntimeIdentifier 之间切换以使我的代码处于活动状态?

这是我要激活的代码片段(未显示为灰色): 在此处输入图像描述

我正在使用 Visual Studio 2017 版本 15.9.23。

这是我的 csproj 的片段:

<PropertyGroup>
  <TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
  <RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">
  <DefineConstants>NETCORE;NETSTANDARD;NETSTANDARD2_0</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net461'">
  <DefineConstants>NET461;NETFULL</DefineConstants>
</PropertyGroup>
<PropertyGroup>
  <DefineConstants Condition="'$(RuntimeIdentifier)' == 'win-x64'">$(DefineConstants);WINDOWS</DefineConstants>
</PropertyGroup>
<PropertyGroup>
  <DefineConstants Condition="'$(RuntimeIdentifier)' == 'linux-x64'">$(DefineConstants);LINUX</DefineConstants>
</PropertyGroup>
4

0 回答 0