Export (0) Print
Expand All

Restricting Developers to Custom Project or Item Types with Enterprise Templates

Visual Studio .NET 2003
 

Steven Powell
Visual Studio Team
Microsoft Corporation

February 2002

Summary: Enterprise Templates and policy make it easy to filter the Add New Item dialog box for a particular project. However, if a custom project item is similar to a standard project item, it might be hard to allow only the custom item to be used without generating inappropriate policy reminders. This paper describes how to avoid this problem by modifying the definition of the standard project item to separate the portion that contains the prototype from the portion that handles identification. Readers should be familiar with Visual Studio .NET and Enterprise Templates. (5 printed pages)

Contents

Introduction
Splitting the Standard Element Definition into Two Parts
Defining the Custom Element
Updating the ELEMENTSET of the Containing Project
Conclusion

Introduction

Visual Studio® .NET Enterprise Templates and policy make it easy to filter the Add New Item dialog box for a particular project. You can also allow only a custom project item, while disallowing a standard item. For some project items that identify to standard project items (C# file, Web form, and so on), if you simply EXCLUDE the standard item, you end up with a policy reminder when you add your custom project item. Your custom project item inappropriately identifies as the standard type, in addition to its custom type.

How can you avoid this problem? You modify the definition of the standard project item to separate the portion that contains the prototype from the portion that handles identification. For example, the scenario below allows only a custom Web form project item while disallowing the standard Web form.

The element definition for projItemWebForm in DAP.tdl (or VSIDE.tdl) appears as follows:

<ELEMENT>
    <ID>projItemWebForm</ID>
    <IDENTIFIERS>
        <IDENTIFIER>
            <TYPE>PROJECTITEM</TYPE>
            <IDENTIFIERDATA>
                <NAME>FileExtension</NAME>
                <VALUE>.aspx</VALUE>
            </IDENTIFIERDATA>
        </IDENTIFIER>
    </IDENTIFIERS>
    <PROTOTYPES>
        <PROTOTYPE>
             [VC#]\CSharpProjectItems\CSharpAddWebFormWiz.vsz</PROTOTYPE>
        <PROTOTYPE>[VB]\VBProjectItems\WebForm.vsz</PROTOTYPE>
    </PROTOTYPES>
</ELEMENT>

Notice that the standard element definition contains both the identification for any Web form (identified via the file extension .aspx) and the prototypes used to filter the Add Item dialog box.

Splitting the Standard Element Definition into Two Parts

To filter out the standard Web form from the Add Item dialog box, break the above element into the following two element definitions:

<ELEMENT>
    <ID>projItemWebForm</ID>
    <IDENTIFIERS>
        <IDENTIFIER>
            <TYPE>PROJECTITEM</TYPE>
            <IDENTIFIERDATA>
                <NAME>FileExtension</NAME>
                <VALUE>.aspx</VALUE>
            </IDENTIFIERDATA>
        </IDENTIFIER>
    </IDENTIFIERS>
</ELEMENT>

<ELEMENT>
    <ID>projItemStandardWebForm</ID>
    <PROTOTYPES>
        <PROTOTYPE>
            [VC#]\CSharpProjectItems\CSharpAddWebFormWiz.vsz</PROTOTYPE>
        <PROTOTYPE>[VB]\VBProjectItems\WebForm.vsz</PROTOTYPE>
    </PROTOTYPES>
</ELEMENT>

This allows you to apply policy to all Web forms, if so desired, while adding the ability to filter out the standard Web forms from the Add Item dialog box.

Defining the Custom Element

Also define an element for your custom Web form, as follows:

<ELEMENT>
    <ID>projItemMyCustomWebForm</ID>
    <PROTOTYPES>
        <PROTOTYPE>
            [VC#]\CSharpProjectItems\CSharpCustomWebForm.vsz</PROTOTYPE>
    </PROTOTYPES>
</ELEMENT>

In the bold line above, you specify the path to your custom Web form prototype or wizard.

Updating the ELEMENTSET of the Containing Project

Finally, if you want to allow the custom Web form and disallow the standard Web form, you need to modify the ELEMENTSET of the containing project. For example, modify the projWebUI element from DAP.tdl to allow the custom Web form and disallow the standard Web form. The updated element is as follows:

<ELEMENT> <!-- Web Project -->
    <ID>projWebUI</ID>
    <CONTEXT>
        <CTXTKEYWORD>WebUI</CTXTKEYWORD>
    </CONTEXT>
    <IDENTIFIERS>
        <IDENTIFIER>
            <TYPE>PROJECT</TYPE>
            <IDENTIFIERDATA>
                <NAME>GLOBAL:TDLELEMENTTYPE</NAME>
                <VALUE>WebUI</VALUE>
            </IDENTIFIERDATA>
        </IDENTIFIER>
    </IDENTIFIERS>
    <PROTOTYPES>
        <PROTOTYPE>
            [EF]\Projects\CSharp Building Blocks\WebUI.vsz
        </PROTOTYPE>
        <PROTOTYPE>
            [EF]\Projects\Visual Basic Building Blocks\WebUI.vsz
        </PROTOTYPE>
    </PROTOTYPES>
    <ELEMENTSET>
        <DEFAULTACTION>EXCLUDE</DEFAULTACTION>
        <ORDER>INCLUDEEXCLUDE</ORDER>
        <INCLUDE>refSystem.Web</INCLUDE>
        <INCLUDE>refSystem.Web.Services</INCLUDE>
        <INCLUDE>catVBCommonProjectItems</INCLUDE>
        <INCLUDE>catCommonProjectItems</INCLUDE>
        <INCLUDE>catWebConfigurationProjectItems</INCLUDE>
        <INCLUDE>catCSCommonProjectItems</INCLUDE>
        <INCLUDE>catWebUIProjectItems</INCLUDE>
        <INCLUDE>catWebFormsControls</INCLUDE>
        <INCLUDE>catDataCodeItems</INCLUDE>
        <INCLUDE>catComponentCodeItems</INCLUDE>
        <INCLUDE>catHTMLProjectItems</INCLUDE>
        <INCLUDE>catHTMLItems</INCLUDE>
        <INCLUDE>refBusinessRulesDll</INCLUDE>
        <INCLUDE>refBusinessFacadeDll</INCLUDE>
        <INCLUDE>refSystemFrameworksDll</INCLUDE>
        <INCLUDE>refWebServiceDll</INCLUDE>
        <INCLUDE>projItemMyCustomWebForm</INCLUDE>
    </ELEMENTSET>
</ELEMENT>

Since the DEFAULTACTION is EXCLUDE, you do not need to explicitly exclude the projItemStandardWebForm element. However, you do need to add the bolded line above to explicitly allow your custom Web form.

Conclusion

The above capabilities allow a project architect to be very specific about what project items can be added to a particular project. While this might not be necessary in all cases, the additional flexibility allows you to decide exactly what is and is not acceptable for your application and capture that knowledge in your Enterprise Template policy.

For more information on Enterprise Templates, see Enterprise Templates for Distributed Applications in the Visual Studio .NET documentation.

Show:
© 2014 Microsoft