Reputation: 3028
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>
Upvotes: 11
Views: 3629
Reputation: 11
if you open a file in the solution rather than the solution itself, the aspx, aspx.vb disappears. Just by opening the solution, rather than a file, the nesting was solved in my case
Upvotes: 0
Reputation: 1
I faced this issue with the Class Library project on .net6. Instead of using the Class Library template use Razor Class Library.
You want the Razor Component option to be in place in the Add new item window.
Upvotes: 0
Reputation: 390
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>
Upvotes: 13
Reputation: 3028
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.
Upvotes: 9
Reputation: 1178
Piggy Backing onto @phihi's answer.
@phihi's solution does actually work with .NET Core 3.1 libraries; but in addition, there must be a .filenesting.json file added at the solution level. It seems that it's also required that the new .filenesting.json lives inside a "Solution Items" folder (folder name may not matter) at the solution level.
Desired nesting settings can be optionally defined stand-alone.. instead of creating a new file with ALL existing default settings, as long as you set "root": false - this essentially appends settings onto the existing default configuration without losing any default settings.
Great success 🤘
Upvotes: 4