Group files in Visual Studio

I'm looking at tidying up my project layout in Visual Studio and I'm wondering if there is any hack, plugin or trick to associate an .xml file with a .cs file of the same name so they appear grouped in my solution navigator/explorer.

Similar to the way the code-behind file is associated with its aspx.

alt text

Any suggestions welcome. Thanks


Solution 1:

In your project file :

<Compile Include="FileA.cs"/>
<Compile Include="FileA.xml">
  <DependentUpon>FileA.cs</DependentUpon>
</Compile>

Or you could use Group Items command of VSCommands 2010 extension.

Edit: Just in case your file is in a folder, don't include the folder name in DependentUpon tag. For example if your file is in Helpers folder:

<Compile Include="Helpers\FileA.cs"/>
<Compile Include="Helpers\FileA.xml">
  <DependentUpon>FileA.cs</DependentUpon>
</Compile>

Solution 2:

If you do not want to slow down you IDE with heavy and proprietary VSCommands extension you can use small extension NestIn instead. It can nothing but group/ungroup files

Solution 3:

For the simple case where the file is a "top level" file, Julien's description works perfectly. However, in the case where the DependentUpon file is in a Folder under the project, this looks different. I personally don't like it because it seems like it could lead to ambiguity, but that's an opinion.

<Compile Include="DataStructs\CKDTree.cs" />
<Compile Include="DataStructs\CClosestObjects.cs" >
    <DependentUpon>CKDTree.cs</DependentUpon>
</Compile>

Notice that the dependent item does NOT include the Folder of the parent. This is true in VS2013... probably true in earlier versions but I have not verified it.