Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio: How to change target framework used by editor?

I have a multi-platform solution with many csproj files configured this way:

<PropertyGroup>
  <TargetFrameworks>net452;netstandard1.4</TargetFrameworks>    
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.4' ">    
  <PackageReference Include="System.Net.Http" Version="4.3.0"/>
  <PackageReference Include="Newtonsoft.Json" Version="9.0.1" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
  <Reference Include="System.Net" />
  <Reference Include="System.Net.Http" />
  <PackageReference Include="Newtonsoft.Json" Version="6.0.8" />
</ItemGroup>

Note that I don't have a TargetFramework element (the singular form). I only have the TargetFrameworks element (the plural form).

The editor assumes netstandard1.4 and all #if NET452 blocks get grayed out and without IntelliSense.

How can I tell Visual Studio editor to recognize a specific target framework (net452, netstandard1.4), and get IntelliSense, at least temporarily?

For reference, I'm using VS2017 Professional version 15.2 (26430.16).

like image 222
fernacolo Avatar asked Aug 10 '17 21:08

fernacolo


People also ask

How do I change from platform target to x64?

To enable x64 as a CPU platform targetClick Configuration Manager. In the Configuration Manager dialog, open the Active solution platform drop-down list box and click <New> …. In the New Solution Platform dialog, select x64 in the Type or select the new platform drop-down list box.

How do I edit a project framework?

Right-click on your project. Select Properties. Select the Application tab. Change the Target Framework to the desired framework.

How do you change the solution platform?

On the menu bar, choose Build > Configuration Manager. In the Active solution platform list, choose a platform for the solution to target, and then choose the Close button. If the platform that you want doesn't appear in the Active solution platform list, choose New.


1 Answers

Here's the answer:

  • Visual Studio 2017 contains 3 combo-boxes on top of the editor. On version 15.1 or above, the leftmost combo allows selecting the framework for editing. That will change syntax highlight of #if blocks according to the selected framework.
  • IntelliSense seems to cover all items declared on TargetFrameworks, even if the text is grayed at editor.

All in all, it was just my learning curve.

like image 179
fernacolo Avatar answered Sep 30 '22 17:09

fernacolo