Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make (.cs) code files expand / collapse underneath another code file in Visual Studio solution explorer?

In Visual Studio 2008/2010 it's possible to place a series of simple .cs code files underneath another .cs file in solution explorer. This behavior is similar to how you see files arranged when adding a WPF UserControl to the solution, where instead a single .cs file can collapse/expand underneath the .xaml file.

How do you make the solution arrange files this way? I've already looked in some of the obvious places, like the file properties pane, the solution and .csproj property pages.

like image 679
T. Webster Avatar asked Dec 28 '22 08:12

T. Webster


2 Answers

I'm not sure there is a way to do this through the Visual Studio UI.

You can do it by manually editing the .csproj file. The trick is to add the <DependentUpon> XML tag to the element you want to appear under another. For example

<Compile Include="Settings.Designer.cs">
  <AutoGen>True</AutoGen>
  <DependentUpon>Settings.settings</DependentUpon>
  <DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
like image 147
JaredPar Avatar answered Dec 31 '22 19:12

JaredPar


You have to edit the .csproj file and add this:

<Compile Include="Form1.Designer.cs">
  <DependentUpon>Form1.cs</DependentUpon>
</Compile>

Or install a plugin like VSCommands in Visual Studio 2010.

like image 42
Jérémie Bertrand Avatar answered Dec 31 '22 20:12

Jérémie Bertrand