How to switch between target frameworks for .NET Core projects in Visual Studio
<p>Say you have a .NET Core project that looks like this:</p>

<pre><code>"frameworks": {
    "net40": {},
    "dotnet5.1": {}
}
</code></pre>

<p>And this is your C# code:</p>

<pre><code>public class Foo
{
    public static void Blah()
    {
#if DOTNET5_1
        DoSomething();
#elif NET40
        DoSomethingElse();
#endif
    }
}
</code></pre>

<p>Now, in Visual Studio when you view the <code>.cs</code> file, one of the <code>#if</code> sections will be grayed out- either <code>DoSomething</code> or <code>DoSomethingElse</code>. Here's how it shows up on my laptop:</p>

<p><a href="https://i.stack.imgur.com/76HD3.png" rel="noreferrer"><img src="https://i.stack.imgur.com/76HD3.png" alt="enter image description here"></a></p>

<p>Is it possible to get VS to 'switch context' between target platforms, so you can view what would be compiled for a particular platform? For example, I might want to check for any red squiggly lines for each framework before actually building the solution.</p>

<p>Any help would be appreciated, thanks!</p>