Visual Studio:如何更改编辑器使用的目标框架?

fer*_*olo 6 .net visual-studio .net-core visual-studio-2017 .net-standard

我有一个多平台解决方案,其中包含许多csproj配置文件:

<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>
Run Code Online (Sandbox Code Playgroud)

请注意,我没有TargetFramework元素(单数形式).我只有TargetFrameworks元素(复数形式).

编辑器假设netstandard1.4并且所有#if NET452块都变灰并且没有IntelliSense.

我怎样才能告诉Visual Studio编辑器识别特定的目标框架(net452,netstandard1.4),并至少暂时获取IntelliSense?

作为参考,我使用的是VS2017 Professional 15.2版(26430.16).

fer*_*olo 6

答案如下:

  • Visual Studio 2017 在编辑器顶部包含 3 个组合框。在 15.1 或更高版本中,最左侧的组合允许选择要编辑的框架。这将#if根据所选框架更改块的语法突出显示。
  • IntelliSense 似乎涵盖了 上声明的所有项目TargetFrameworks,即使文本在编辑器中呈灰色也是如此。

总而言之,这只是我的学习曲线。