Skip to content

Instantly share code, notes, and snippets.

@ArcanoxDragon
Created September 7, 2021 18:00
Show Gist options
  • Save ArcanoxDragon/ef1bb413a1d86285e171801f282cf38c to your computer and use it in GitHub Desktop.
Save ArcanoxDragon/ef1bb413a1d86285e171801f282cf38c to your computer and use it in GitHub Desktop.
MSBuild Automatic Sub-File Nesting

This snippet allows Visual Studio to automatically nest .cs files with a filename "suffix" under parent .cs files.

For example, "MyFile.Partial.cs" would be nested under "MyFile.cs".

<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<NestedItem Include="@(Compile)">
<Parent>%(Identity)</Parent>
<Children>%(RelativeDir)%(Filename).*.cs</Children>
</NestedItem>
</ItemGroup>
<ItemGroup>
<Compile Update="@(NestedItem->'%(Children)')">
<DependentUpon>%(NestedItem.Parent)</DependentUpon>
</Compile>
</ItemGroup>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment