DotNetWise©

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.


    HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\9.0
    {
    NoRemove 'Projects'
    {
    NoRemove '{E24C65DC-7377-472b-9ABA-BC803B73C61A}' = s '#2143'
    {
    RelatedFiles
    {
    .PrimaryExtension
    {
    val 'RelationType' = d 'typeValue'
    val ‘Suffix’ = s ’somesuffix’
    .RelatedExt1
    .RelatedExt2
    .RelatedExtn
    }
    }
    }
    }
    }

    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.
        foo.xsd
    foo.xsx
    foo.xsc
    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:
       .htm        
    .js
    .css
    .js
    .min.js
    .lang.js
    .css
    .lang.js
    So your files can be nested like this:
    Template.htm
    Template.js
    Template.min.js
    Template.lang.js
    Template.lang.min.js
    Template.css
    Template.lang.css

    • Value = 2 – this defines a basename.primaryextension to basename.primaryext.relatedextension relationship.
        foo.aspx
    foo.aspx.vb

    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:
        foo.xsd
    foo_bar.xsx
    foo_bar.xsc
    foo_foobar.xsx
    foo_foobar.xsc

    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