56

Possible Duplicate:
Group files in Visual Studio

The problem is, that I want to group partial class files in a way in the Solution Explorer, that visual Studio displays a [+] in front of the filename which I than can expand to see all other dependant files.

But my classes are shown in two rows below each other:

> CustomerServiceDao.cs
> CustomerServiceDao.Query.cs

The result I want to have is something like that.

+ CustomerServiceDao.cs
    > CustomerServiceDao.Query.cs

Is there any naming convention which I have to follow in order to show the partial files grouped?

EDIT

It works. That's great. But are there any naming conventions? e.g. ascx does it by default ...

Jan Schultke
  • 17,446
  • 6
  • 47
  • 96
BitKFu
  • 3,649
  • 3
  • 28
  • 43

4 Answers4

76

If you open your .csproj as a text file (or choose "Unload Project" from the context menu in Solution Explorer for the project, followed by "Edit myproject.csproj") you can change it to show the relevant files in Solution Explorer in the style you wish.

Look for:

<Compile Include="CustomerServiceDao.cs" />
<Compile Include="CustomerServiceDao.Query.cs" />

And edit it to be as this:

<Compile Include="CustomerServiceDao.cs" />
<Compile Include="CustomerServiceDao.Query.cs">
    <DependentUpon>CustomerServiceDao.cs</DependentUpon>
</Compile>

There's no way to do this directly within the Visual Studio editor, but given the extensibility model that VS2k10 provides, it probably won't be long before someone produces something.

Update: The latest version of VSCommands claims to support doing this for you:

Latest version supports grouping items from IDE (so you don't have to hand-hack project file with DependentUpon).

Carlos Muñoz
  • 17,397
  • 7
  • 55
  • 80
Rob
  • 45,296
  • 24
  • 122
  • 150
  • 1
    Correct link for VSCommands is http://visualstudiogallery.msdn.microsoft.com/en-us/d491911d-97f3-4cf6-87b0-6a2882120acf - I'll update the answer with it shortly, once I've checked if it actually works =) – Rob Sep 01 '10 at 19:30
  • That's really cool ;) I'm impressed. VSCommands works like a charme. – BitKFu Sep 01 '10 at 19:39
  • I could not get this to nest item a within item b where item b is not a sibling of a. BUT NestIn mentioned in Dao's answer does do this. – Myster Mar 07 '12 at 03:57
  • If you edit the .csproj file first, add a file at the physical location. And as mentioned in the linked answer, unload the project, right-click, edit, save and then reload the project. http://stackoverflow.com/questions/5129090/how-to-edit-csproj-file – user2330678 Mar 07 '14 at 22:11
  • I could not get this to work in VSCommands for VS2013. I did not even see it documented for that version. – JamesFaix Nov 02 '15 at 16:20
  • Actually, I did get it to work in VSC, it's just not documented. It's a little nicer than NestIn because you don't have to select the root file to ungroup a child file. – JamesFaix Nov 02 '15 at 16:28
26

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

Dao
  • 2,784
  • 3
  • 28
  • 36
  • +1 I could not get VSCommands to nest item a within item b where item b is not a sibling of a. BUT NestIn does, yay! ... but sometimes un-nest does not work :-\ – Myster Mar 07 '12 at 03:58
10

You can achieve this if you manually edit your .csproj file.

Just right click you project, hit Unload Project.

From there, right click and hit Edit project.csproj

Look for the Compile elements. Add a DependentUpon sub-element like this:

<Compile Include="CustomerServiceDao.cs" />
<Compile Include="CustomerServiceDao.Query.cs">
    <DependentUpon>CustomerServiceDao.cs</DependentUpon>
</Compile>
The Hungry Dictator
  • 3,444
  • 5
  • 37
  • 53
Matt Brunell
  • 10,141
  • 3
  • 34
  • 46
  • It works. That's great. But are there any naming conventions? e.g. ascx does it by default ... – BitKFu Sep 01 '10 at 19:23
  • @BitKFu, Some project types do it by default because that's the way they've been coded. There's no naming convention that will help you here, I'm afraid. I have just found a plug-in (mentioned in my answer), that claims it'll do it for you though! =) – Rob Sep 01 '10 at 19:26
  • I really would like to give both of you the reputation. Very good answers, but I have to choose one. – BitKFu Sep 01 '10 at 19:40
2

try using Group/ungroup items by installing VScommands1.2

Pratik
  • 21
  • 1