I have a multi target C# project that targets .Net Framework 4.8 and .NET 7.0. Some of my source code files are included only for one of the above target frameworks. The Solution Explorer shows the project from the perspective of .NET 7.0.
My Question is:
Is it possible to switch this perspective so that I can see the include files from the perspective of a specific target framework that is specified in my project file?
My csproj file looks something like this:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net7.0;net48</TargetFrameworks>
..
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<EnableDefaultContentItems>false</EnableDefaultContentItems>
<EnableDefaultItems>false</EnableDefaultItems>
..
</ProjectGroup>
..
<ItemGroup>
<Compile Include="sourcecode_A.cs" />
<Compile Include="sourcecode_B.cs" />
<Compile Include="sourcecode_C.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net7.0'">
<Compile Include="sourcecode_X.cs" />
..
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)'=='net48'">
<Compile Include="sourcecode_Y.cs" />
..
</ItemGroup>
..
</Project>
The Solution Explorer only shows files (from Perspective .net 7.0)
Thanks to the hint of @wenbin-geng I solved the problem as follows:
I added two more build configurations to my solution: net48_Debug and net7_0_Debug.
I modified my project file:
<PropertyGroup>
<TargetFrameworks>net7.0;net48</TargetFrameworks>
<TargetFramework Condition="'$(Configuration)'=='net48_Debug'">net48</TargetFramework>
<TargetFramework Condition="'$(Configuration)'=='net7_0_Debug'">net7.0</TargetFramework>
..
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<EnableDefaultContentItems>false</EnableDefaultContentItems>
<EnableDefaultItems>false</EnableDefaultItems>
..
<Configurations>Debug;Release;net48_Debug;net7_0_Debug</Configurations>
</ProjectGroup>
Now it is possible to switch the target framework by selecting a build configuration.