Search code examples
visual-studiosolution-explorer

Display a file hierarchically under another file in Visual Studio


In Visual Studio, I'd like to show a hierarchical relationship between certain files.

A typical ASP.NET WebForms application provides an example of what I want. Say that I have a file named Page.aspx. Files named Page.aspx.cs and Page.aspx.designer.cs would typically appear hierarchically below Page.aspx in Solution Explorer.


Solution

  • If you want File A to appear hierarchically under File B in Solution Explorer, do the following:

    Open your project file, go to the <Content Include> (or <None Include>, or what have you) node for File A and add a <DependentUpon>File B</DependentUpon> child to it. The result should look similar to this:

    <Content Include="File A">
      <DependentUpon>File B</DependentUpon>
    </Content>`