In Visual Studio 2019 Web Projects, file nesting in the Solution Explorer works like a charm. If you add a file named ClassA.cs and another file named ClassA.Custom.cs they get nested as it should be.

But for Class or Shared Library Projects it doesn't work at all. It doesn't matter if you change the settings to "Default" or "Web" or even add a custom File Nesting Setting.

Is there a way, to configure Visual Studio 2019 so that file nesting also works in Class Library Projects and alike?
I know one could change the *.csproj files manually to add Entries with the <DependentUpon> Tag like it was in earlier Visual Studio versions, but i really don't like the idea of changing this manually for all the classes i have.
<Compile Update="$(ProjectDir)\Person.*.cs">
<DependentUpon>$(ProjectDir)\Person.cs</DependentUpon>
</Compile>
For the people using Visual Studio 2022 and non-web projects, this is the solution from Github that helped me to fix it.
To enable configurable file nesting for non-web projects in VS 2022, add this to your .csproj file:
<ItemGroup>
<ProjectCapability Include="ConfigurableFileNesting" />
<ProjectCapability Include="ConfigurableFileNestingFeatureEnabled" />
</ItemGroup>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With