Grouping files in solution explorer

Hi,

I have files in various subdirectories that I want to include in the Solution Explorer. It is getting a little tedious to "Add Existing Item" with a link (sometimes I click the button before changing it to "link" whereby I have to delete the copied file - bad UI design IMO). The files appear as a flat list in the explorer which is also a pain.

I've discovered I can use <CSFile Include="..\Display\*.cs/> in my .csproj file to avoid having to enter every file manually.

However, I still have a few problems:

1) I still get a flat file list in the solution explorer. I've tried using <Filter ...> (used in .vcproj files) but VS doesn't like it.

2) I haven't figured out how to identify forms and link partial classes together. E.g. How do I tag "../Display/ChartWindow.cs" as a <SubType>Form</SubType> and how I can associate "../Display/ChartWindow.designer.cs" with "../Display/ChartWindow.cs". Interestingly, VS picks up the .resx relationship.

Any help appreciated. I've run out of terms to Google. There does not appear to be a central document describing the .csproj schema (even the MSBUILD schema does not appear comprehensive i.e. CSFile - let alone providing helpful documentation).

Many thanks.



Answer this question

Grouping files in solution explorer

  • LeeroyB

    Hello All.

    ehjensen:

    This snippet might be of use to you:


    <ItemGroup>
    <
    Content Include="..\..\..\..\My Images\images\Education\CBR003161_LoRes.jpg">
    <
    Link>NewFolder1\CBR003161_LoRes.jpg</Link>
    </
    Content>
    <
    Content Include="NewFolder1\CBR003860_LoRes.jpg" />
    </
    ItemGroup>


    The first content tag is a file included as a link, in a sub-folder in Solution Explorer named NewFolder1, and second content tag is a file included by copy, in the same sub-folder.

    HTH.



  • Harry Hunt

    That works like a charm for individual files. Thank you!

    Any thoughts about how this might work with globbing (e.g. *.cs) I've tried a few variations inc'l <link>foo\*.cs</link> to no avail.

  • Chris Langsenkamp

    Hello All.

    Eric:

    You're welcome. I did a little poking around MSDN, and found this. It might be useful.

    HTH.



  • Loki70

  • mteverest

    Thank you Mark!

  • Maurice Reeves

    Hello All.

    Eric:

    I'm not sure you could make that work straight from the .csproj file. You'd probably have to have some kind of intermediary script acting on an XML source file, like an XLST or something. The content tags are individual items, so you'd have to have the "*.cs" situated in a source XML file that the XLST would transform into the .csproj file.

    HTH.



  • Grouping files in solution explorer