Defining an element of a project as a sub-element of another

 
 
  • Gérald Barré

In the solution explorer you can see nested files:

Let's see how to do the same with the two files Class1.cs and Class1.Custom.cs. The trick is in the project file (csproj). You need to look for the Class1.Custom.cs file in it and indicate which item is its parent.

MSBuild project file
<Compile Include="Class1.cs" />
<Compile Include="Class1.Custom.cs">
    <DependentUpon>Class1.cs</DependentUpon>
</Compile>

And here's the result:

Do you have a question or a suggestion about this post? Contact me!

Follow me:
Enjoy this blog?Buy Me A Coffee💖 Sponsor on GitHub