0

I am using preprocessor conditions in my source code to emit different code based on the RuntimeIdentifier. Though, the code is always grayed out since I can't choose a context that is based on both TargetFramework and RuntimeIdentifier.

In the Visual Studio navigation bar I can switch between net461 and netstandard2.0. How can I switch between both TargetFramework AND RuntimeIdentifier to make my code active?

Here is the code snippet I want to make active (not grayed out): enter image description here

I'm using Visual Studio 2017 version 15.9.23.

Here is a snippet of my 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>
Simon
  • 83
  • 7
  • Switching among target frameworks is a mandatory feature of VS, as compilation profiles differ. However, your wishes on runtime identifier is not mandatory, because it's just ordinary conditional compilation (as you use your own constants. BTW, why not use runtime OS detection? https://stackoverflow.com/questions/38790802/determine-operating-system-in-net-core – Lex Li Jun 05 '20 at 14:32
  • Thanks Lex Li. I am familiar with runtime detection. Thanks! – Simon Jun 06 '20 at 17:53

0 Answers0