应该为不同版本的框架构建一个项目。这是 csproj 文件:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net45;</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Some.HttpClient" Version="1.0.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<Reference Include="System.Net.Http" />
</ItemGroup>
</Project>
对于这样一个项目,我只对 进行语法高亮.net standard 2.0,而对于net 4.5它,它根本没有经过验证。这是来自 Visual Studio 的屏幕截图:
问题:有什么方法可以切换net45到检查 VisualStudio 中的编译错误以进行构建net45?

一切都变得非常简单,但并不那么明显。
target framework可以在导航面板上选择所需的一项: