Wednesday, September 30, 2009

Visual Studio 2008 Custom Nested Files

After googling for months I have finally succeeded to nest custom files on Visual Studio 2008.

There are different techniques posted by other users, all are good but they only apply to specific situations.
  1. Using a macro for nesting the files on the fly as Christoph De Baene describes here
    Very nice, but this doesn't work for WebSites, as there is no .csproj involved to store the nesting information.

  2. Creating a project template -or- item template i.w. with GAT (Guidance Automation Toolkit) and add the ability to nest custom files as Mads Kristensen describes here
    Again nice, but not suitable for simple cases and still doesn't apply to WebSites

  3. Defining custom nesting rules in registry - suitable for websites as Bill Hie describes here.
    Below is the quoted tip updated for VS2008 and on a Windows Server 2008 x64
    Note that the root path of the VisualStudio might be different on another version of Windows.

    Defining Related Files

    The web project system has the ability to nest one file type under another file type in the solution explorer. These relationships are all done by pattern matching the file names and are driven by entries under the RelatedFiles key.

    NoRemove 'Projects'
    NoRemove '{E24C65DC-7377-472b-9ABA-BC803B73C61A}' = s '#2143'
    val 'RelationType' = d 'typeValue'
    val ‘Suffix’ = s ’somesuffix’

    PrimaryExtension - This is the extension of the “primary” file - the one that will contain the nested files.

    RelationType - This value defines the pattern that is used to form the relationship. The supported typeValue’s are:

    • Value = 1 this defines a simple relationship based on the base name of the parent file. basename.PrimaryExtension will have one or more related files called basename.RelatedExt1, basename.RelatedExt2, etc.
    This can be very nice as you can define multiple nest levels.
    For example if .lang would be the extension for the language specific files and .min for the minified javascript files we can define:
    So your files can be nested like this:

    • Value = 2 - this defines a basename.primaryextension to basename.primaryext.relatedextension relationship.

    Suffix - Optional. Only used by the simple relationship (RelationType = 1), to extend the simple relationship to include semi-colon delimited list of possible suffixes to the base name. If Suffix was set to ‘_bar;_foobar’, the simple relationship example above becomes:

    To include foo.xsx and foo.xsc as well as the suffix varieties, one of the suffixes needs to be the empty string as denoted by the leading semi-colon: ‘;_bar;foobar’

    .RelatedExt1…n - The file extensions which will appear under the primary file. In the example above, it would register two extensions .xsx, and .xsc.

No comments:

Post a Comment

Blog powered up by Blogger