ソース コードでプリプロセッサ条件を使用して、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>