Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filenesting not working for Class or Shared Library Projects

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.

enter image description here

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.

enter image description here

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>
like image 941
phifi Avatar asked Mar 04 '26 17:03

phifi


1 Answers

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>
like image 135
Taylan Yuksel Avatar answered Mar 08 '26 22:03

Taylan Yuksel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!