visual-studio-2019solution-explorer

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>

Solution

  • Original Answer:

    There is an issue about this topic active on Github.com and Developer Community:

    A workaround for this problem exists - at least working for .Net Standard 2.0. Add the following lines to your *.csproj file:

    <ItemGroup> <ProjectCapability Include="DynamicDependentFile" /> <ProjectCapability Include="DynamicFileNesting" /> </ItemGroup>

    Update:

    This issue should be fixed from Visual Studio 2019 Verison 16.7 onwards.