Export (0) Print
Expand All

Adding Projects that Do Not Support Policy to an Enterprise Template

Visual Studio .NET 2003
 

Steven Powell
Visual Studio Team
Microsoft Corporation

February 2002

Summary: As part of an Enterprise Template, you might want to include a project type that does not directly support policy. This paper describes the steps necessary to include this type of project in an Enterprise Template: creating a custom wizard script; making Visual Studio aware of the custom wizard; attaching the custom wizard to an Enterprise Template project. Readers should be familiar with Visual Studio .NET and Enterprise Templates. (4 printed pages)

Contents

Introduction
Creating the Custom Wizard Script
Making Visual Studio Aware of the Custom Wizard
Attaching the Custom Wizard to an Enterprise Template Project

Introduction

In many cases, you might want to include a project type that does not directly support policy as part of a Microsoft® Visual Studio® .NET Enterprise Template project. A good example of this is a Visual Studio database project (.dbp). Including a database project as part of an Enterprise Template project requires more work than including standard language projects (Microsoft® Visual Basic®, Visual C#™, or Visual C++®).

To add a database project to an Enterprise Template, you must use a custom project wizard to invoke the database project, rather than attach it directly to the parent Enterprise Template project (.etp) as a static project prototype. The work breaks down into the following steps:

  • Create the custom wizard script to launch the database project.
  • Make Visual Studio aware of the custom wizard.
  • Attach the custom wizard to an Enterprise Template project.

Creating the Custom Wizard Script

As a starting point for creating a custom wizard, you can copy existing code/script from a standard wizard that is included with Visual Studio. Beneath the Visual Studio installation folder, find the following hierarchy:

C:\Program Files

    Microsoft Visual Studio .NET

        EnterpriseFrameworks

            EFWizards

                    csharpdllwiz

                            scripts

                                    1033

                            templates

                                    1033

To create your own custom wizard, copy the csharpdllwiz folder, paste it in the EFWizards folder, and rename the copy "databasewiz". Delete the files in databasewiz\templates\1033, as you will not be cloning any template files with this wizard. Within the databasewiz\scripts\1033 folder is the file you modify, Default.js.

Initially, this contains the following functions:

  • function OnFinish(selProj, selObj)
  • function GetCSharpTargetName(strName, strProjectName)
  • function DoOpenFile(strName)
  • function SetFileProperties(oFileItem, strFileName)
  • function CollapseProjectNode( oProj )

Since you will not clone any template files as part of this wizard, you can delete all but OnFinish() and CollapseProjectNode(). Leave the CollapseProjectNode() function unchanged. You need to update the OnFinish() function as follows. The bold lines are critical, as they create the project using the specified template.

function OnFinish(selProj, selObj)
{
    var oldSuppressUIValue = true;
    try
    {
        oldSuppressUIValue = dte.SuppressUI;
        var bSilent = wizard.FindSymbol("SILENT_WIZARD");
        dte.SuppressUI = bSilent;

        var strProjectName = wizard.FindSymbol("PROJECT_NAME");
        var strProjectPath = wizard.FindSymbol("PROJECT_PATH");
        var strTemplatePath = wizard.FindSymbol("TEMPLATES_PATH");
        var strTemplateFile = strTemplatePath + 
            "\\..\\..\\..\\..\\projects\\visual basic building blocks\\"
            + wizard.FindSymbol("EFT_PROTOTYPE"); 

        var oTarget = wizard.FindSymbol("TARGET");

        var prjItem = oTarget.AddFromTemplate(strTemplateFile,
          strProjectPath+"\\"+strProjectName +".dbp");
        
        return 0;
    }
    catch(e)
    {   
        switch(e.number)
        {
        case -2147024816 /* FILE_ALREADY_EXISTS */ :
            return -2147213313;

        default:
            SetErrorInfo(e);
            return e.number;
        }
    }
    finally
    {
        dte.SuppressUI = oldSuppressUIValue;
    }
}

The wizard script determines where the Enterprise Templates reside (TEMPLATES_PATH) and points to the folder where you placed the copy of the standard .dbp file. The AddFromTemplate() method then launches the database project UI, prompting for the required information.

Making Visual Studio Aware of the Custom Wizard

To enable Visual Studio to launch this custom wizard, you need to create a top-level .vsz file. Create it in the same folder where you place your other custom building block wizards. In this case, create it under C:\Program Files\Microsoft Visual Studio .NET\EnterpriseFrameworks\Projects\Visual Basic Building Blocks. The Database.vsz file looks as follows:

VSWIZARD 7.0
Wizard=VsWizard.VsWizardEngine
Param="WIZARD_UI = FALSE"
Param="WIZARD_NAME = Database"
Param="PROJECT_TYPE = ETPROJ"
Param="SCRIPT_COMMON_RELATIVE_PATH = VBPROJ"
Param="EFT_PROTOTYPE = Database1.dbp"

Attaching the Custom Wizard to an Enterprise Template Project

To automatically create this database project when a template is instantiated, you must associate the custom wizard with the containing .etp project. Add the following section to the .etp project file:

<SUBPROJECTWIZARDS>
    <WIZARD>
        <FILE>
            ..\..\proxyprojects\Visual Basic Building Blocks\Database.vsz
        </FILE>
    </WIZARD>
</SUBPROJECTWIZARDS>

After you complete the steps above, creating a project from the Enterprise Template will launch the Database Project wizard. You can use this same mechanism to include other projects that do not support policy (for example, Setup projects). This allows the project architect to include everything a project needs within an Enterprise Template.

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

Show:
© 2014 Microsoft