http://www.developer.com/

Back to article

Creating an Application Development Framework Using Enterprise Templates, Part 2


June 20, 2003

In the first part of this article, we looked at different building blocks that provide the core foundation for building the enterprise template. In this part, we will demonstrate how to take the building blocks and convert them into an application development framework that can be used as the starting point for building new .NET applications.

We will split the enterprise template construction process into the following steps:

  • Define the application structure that can be saved as an enterprise template
  • Create a policy file and associate it with the application structure
  • Convert the application structure and the policy file into an enterprise template
  • Customize the Visual Studio.NET IDE to enable our template to be available in the New Project dialog box
  • Customize the template by adding useful information such as help topics and so on

Before we look at the above steps, we will need to clearly identify the structure and naming scheme for our enterprise template.

Structure and naming scheme for the template

When you are creating an enterprise template, it is very important to determine, in advance, the structure and the naming scheme for our enterprise template. When creating customized enterprise templates, we can use the Enterprise Template Projects (that have the .etp file extension) as the starting point. The following chart provides information on the directory structure as well as the naming standard that we are going to adopt.

Please refer to Part 1 of this article for more information on the different reusable blocks. Now that we have defined the initial application structure and the naming scheme, let us go ahead and create this initial structure using Visual Studio.NET. To accomplish this, we will select File->New Project and then expand Other Projects in the Project Types pane and select theEnterprise Template Projects folder. In the templates pane, we will select Enterprise Template Project, name the project CustomDistributedAppTemplate, and then create the project in the C:\Projects folder, as shown below.

Once the project is created, we then can add the nested enterprise templates (such as UIProjects, WebServiceProjects, BusinessFacadeProjects, BusinessRulesProjects, DataAccessProjects, and SystemFrameworkProjects) to the CustomDistributedAppTemplate project.

To perform this, we will select CustomDistributedAppTemplate in the solution explorer and then right-click on it to select Add->New Project. In the New Project dialog box, we will select Enterprise Template Projects in the Project Types pane and Enterprise Template Project in the Templates pane. Now enter UIProjects as the name of the project and click OK. This will create a UIProjects project under CustomDistributedAppTemplate. We will repeat the same process for creating the other projects (changing the project names to WebServiceProjects, BusinessFacadeProjects, BusinessRulesProjects, DataAccessProjects, and SystemFrameworkProjects) as well.

Adding building blocks to enterprise template projects

With the addition of all the nested enterprise templates to the master template, we have completed the creation of an initial application structure. Now, we can add the individual building blocks that we talked about earlier to the template. We will start by adding the Utilities project to the SystemFrameworkProjects project. Before we do this, we will copy the Utilities project folder to the SystemFrameworkProjects folder using Windows Explorer. This is required because this template folder structure will be replicated when new projects are created from the template. Once we copy the folder, we then can add the project to the template by right-clicking on the SystemFrameworkProjects and selecting File->Add Existing Project. In the existing project dialog box, we then select the Utilities.csproj file to add the project.

We will repeat the same process for the other projects such as ExceptionManagement, Encryption, and ConfigurationHandler and add them to the SystemFrameworkProjects template. Similarly, we will add the SqlDataAccess project to the DataAccessProjects template. We also repeat the same process for WebUI and WebService projects by adding them to UIProjects and WebServiceProjects templates respectively.

After adding all of the above projects to the CustomDistributedAppTemplate, the solution explorer should look like the following figure.

Now that we have created the application structure, we need to associate an application policy file with the template.

Associating the policy file with the template

Before we create a policy file for our template, let us understand what a policy file is and how relates to a new language called TDL. Basically, a policy file allows us to control the Visual Studio.NET environment by allowing us to clearly define the configuration settings. Within the policy file, we could do things such as setting compiler options, pointing VS.NET to display custom help topics, restricting project references, and so on. The policy file is described using a language named TDL (Template Description Language), that is based on XML.

For our template, instead of creating a policy file from scratch, we will copy the existing policy file (that is supplied by Microsoft along with VS.NET) and customize it. The procedure to associate a policy file with the template is detailed below.

  • Select CustomDistributedAppTemplate from the solution explorer and right-click on it to select Properties from the context menu.
  • Click the ... icon that is right next to the Policy file property and select the DAP.tdl file.
  • Make a copy of the DAP.tdl file and rename it to CustomDistributedAppTemplate.tdl.

Once we associate a policy file to the template project, we then can easily customize the policy file to our requirements. We will be modifying the contents of the policy file in the later parts of this article.

Converting the initial implementation into a template

In this section, we will see how to convert the initial application implementation into a template. To accomplish this, we will have to go through the following steps.

  • Copy the template folder to appropriate location
  • Remove unused files
  • Edit the template project files to remove unnecessary entries
  • Modifying the web project to use relative URLs
  • Associate the policy file with the template projects
  • Make the template available to other users

We will take a detailed look at all of the above steps one by one.

Copying the template folder to appropriate location

When you create one of the Microsoft-supplied enterprise template projects using VS.NET, VS.NET will internally determine the contents of that new project based on the contents within the folder <Drive Name>:\Program Files\Microsoft Visual Studio .NET\EnterpriseFrameworks\Projects\<Name of the template project that you are trying to create>. In our case, because we are creating our own template, we need to copy the contents of our template to the above-mentioned folder. For this reason, we will copy the entire CustomDistributedAppTemplate folder to the above folder. This will copy all the projects within our template except the WebUI and WebService projects because they were created in the IIS Default Web site path. So, we will manually copy the WebUI and WebService projects to the WebUIProjects and WebServiceProjects folders, respectively, that are present within the CustomDistributedAppTemplate folder.

Removing unused files

Unlike distributed applications, the enterprise templates do not use of all the files and folders (files such as .eto, .sln, .suo, and folders such as bin and obj) that appear in the CustomDistributedAppTemplate folder. When you create a new project using our template, VS.NET will again create all the files and folders for you, so it is recommended that we remove these files to avoid confusion at the later stages.

Editing the template project files to remove unnecessary entries

When you create a new project using VS.NET, VS.NET will create a new unique identifier that is specific to your project. Because we are creating a template (from which other projects will be created), we will remove the project-specific unique identifier entries by removing the GUIDPROJECTID element in the following files.

  • <Drive Name>:\Program Files\Microsoft Visual Studio .NET\EnterpriseFrameworks\Projects\ CustomDistributedAppTemplate CustomDistributedAppTemplate.etp
  • <Drive Name>:\Program Files\Microsoft Visual Studio .NET\EnterpriseFrameworks\Projects\ CustomDistributedAppTemplate \UIProjects.etp
  • <Drive Name>:\Program Files\Microsoft Visual Studio .NET\EnterpriseFrameworks\Projects\ CustomDistributedAppTemplate \WebServiceProjects.etp
  • <Drive Name>:\Program Files\Microsoft Visual Studio .NET\EnterpriseFrameworks\Projects\ CustomDistributedAppTemplate \DataAccessProjects.etp
  • <Drive Name>:\Program Files\Microsoft Visual Studio .NET\EnterpriseFrameworks\Projects\ CustomDistributedAppTemplate \SystemFrameworkProjects.etp

In the above files, we need to identify the GUIDPROJECTID element and remove it. The number of times this element appears in an .etp file depends on the number of projects that are associated with that template. For example in the SystemFrameworkProjects.etp file, you will see this element four times because we have already associated four projects to the SystemFrameworkProjects template. The GUIDPROJECTID element will look somewhat similar to the following.

        <GUIDPROJECTID>{059A52C0-7006-43AA-97F5-86C442152386}
        </GUIDPROJECTID>

Modifying the Web projects to use relative URLs

If you open up the UIProjects.etp file or WebServiceProjects.etp file, you will see that the project creation location is hard-coded. To avoid this, we will open up those files and modify the File element to use a relative path location. After modification, the Views and References elements in the UIProjects.etp file should look like the following.

<Views>
  <ProjectExplorer>
    <File>WebUI/WebUI.csproj</File>
  </ProjectExplorer>
</Views>
<References>
  <Reference>
    <FILE>WebUI/WebUI.csproj</FILE>
    <REQUIRESURL>1</REQUIRESURL>
  </Reference>
</References>

In the Reference element, note that we have also added the REQUIRESURL element to prompt the user to enter the location of the Web service.

We make similar changes to the WebServiceProjects.etp file, as well.

<Views>
  <ProjectExplorer>
    <File>WebService/WebService.csproj</File>
  </ProjectExplorer>
v/Views>
<References>
  <Reference>
    <FILE>WebService/WebService.csproj</FILE>
    <REQUIRESURL>1</REQUIRESURL>
  v/Reference>
</References>

Associating the policy file with the template projects

As we said earlier, the policy file is the one that provides the core foundation for successfully creating enterprise templates. For the policy file to do its job, we need to identify each of the previously created templates and building blocks as ELEMENT nodes, so that the policy file can link them up together to provide a consistent view for our enterprise template. To accomplish this, we will make the following changes.

  • Add a GLOBALENTRY element in the .etp projects.
  • Add a UserProperties element in the .csproj files.

The following table describes the changes that we need to make.

FileName Changes
CustomDistributedAppTemplate.etp
<GLOBALS>
  <GLOBALENTRY>
  <NAME>TDLFILE</NAME>
  <VALUE>CustomDistributedApp
         Template.TDL</VALUE>
  </GLOBALENTRY>
  <GLOBALENTRY>
    <NAME>TDLELEMENTTYPE</NAME>
    <VALUE> etpCustomDistributedApp
            Template</VALUE>
  </GLOBALENTRY>
</GLOBALS>
BusinessFacadeProjects.etp
<GLOBALS>
  <GLOBALENTRY>
    <NAME>TDLFILE</NAME>
    <VALUE>CustomDistributedApp
           Template.TDL</VALUE>
  </GLOBALENTRY>
  <GLOBALENTRY>
    <NAME>TDLELEMENTTYPE</NAME>
    <VALUE> etpBusinessFacade
            Projects</VALUE>
  </GLOBALENTRY>
</GLOBALS>
BusinessRulesProjects.etp
<GLOBALS>
  <GLOBALENTRY>
    <NAME>TDLFILE</NAME>
    <VALUE>CustomDistributedApp
           Template.TDL
    </VALUE>
  </GLOBALENTRY>
  <GLOBALENTRY>
    <NAME>TDLELEMENTTYPE</NAME>
    <VALUE> etpBusinessRules
            Projects</VALUE>
  </GLOBALENTRY>
</GLOBALS>
DataAccessProjects.etp
<GLOBALS>
  <GLOBALENTRY>
    <NAME>TDLFILE</NAME>
    <VALUE>CustomDistributedApp
           Template.TDL
    </VALUE>
  </GLOBALENTRY>
  <GLOBALENTRY>
    <NAME>TDLELEMENTTYPE</NAME>
    <VALUE> etpDataAccess
            Projects</VALUE>
  </GLOBALENTRY>
</GLOBALS>
SystemFrameworkProjects.etp
<GLOBALS>
  <GLOBALENTRY>
    <NAME>TDLFILE</NAME>
    <VALUE>CustomDistributedApp
           Template.TDL</VALUE>
  </GLOBALENTRY>
  <GLOBALENTRY>
    <NAME>TDLELEMENTTYPE</NAME>
    <VALUE> etpSystemFramework
            Projects</VALUE>
  </GLOBALENTRY>
</GLOBALS>
UIProjects.etp
<GLOBALS>
  <GLOBALENTRY>
    <NAME>TDLFILE</NAME>
    <VALUE>CustomDistributedApp
           Template.TDL</VALUE>
  </GLOBALENTRY>
  <GLOBALENTRY>
    <NAME>TDLELEMENTTYPE</NAME>
    <VALUE> etpUIProjects</VALUE>
  </GLOBALENTRY>
</GLOBALS>
WebServiceProjects.etp
<GLOBALS>
  <GLOBALENTRY>
    <NAME>TDLFILE</NAME>
    <VALUE>CustomDistributedApp
           Template.TDL</VALUE>
  </GLOBALENTRY>
  <GLOBALENTRY>
    <NAME>TDLELEMENTTYPE</NAME>
    <VALUE> etpWebServiceProjects
    </VALUE>
  </GLOBALENTRY>
</GLOBALS>
SqlDataAccess.csproj
<UserProperties
  TDLFILE = "CustomDistributedApp
  Template.TDL" TDLELEMENTTYPE =
  "SqlDataAccess"/>
ConfigurationHandler.csproj
<UserProperties
  TDLFILE =
  "CustomDistributedAppTemplate.TDL"
  TDLELEMENTTYPE =
  "ConfigurationHandler"/>
Encryption.csproj
<UserProperties
  TDLFILE =
  "CustomDistributedAppTemplate.TDL"
  TDLELEMENTTYPE = "Encryption"/>
ExceptionManagement.csproj
<UserProperties
  TDLFILE =
  "CustomDistributedAppTemplate.TDL"
  TDLELEMENTTYPE =
  "ExceptionManagement"/>
Utilities.csproj
<UserProperties
  TDLFILE =
  "CustomDistributedAppTemplate.TDL"
  TDLELEMENTTYPE =
  "Utilities"/>
WebUI.csproj
<UserProperties
  TDLFILE =
  "CustomDistributedAppTemplate.TDL"
  TDLELEMENTTYPE = "WebUI"/>
WebService.csproj
<UserProperties
  TDLFILE =
  "CustomDistributedAppTemplate.TDL"
  TDLELEMENTTYPE = "WebService"/>

Any template that is not visible to the user will not be of any value. So, the next step is to make the template available in the New Project dialog box so that it can be found and used by others.

Making the template available to other users

In this step, we will instruct Visual Studio.NET to display our enterprise template in the New Project dialog box. When Visual Studio.NET displays the New Project dialog box, it basically reads entries from a file that has the extension .vsdir. The .vsdir file needs to be available in the ProxyProjects folder that is present in "<Drive Name>:\Program Files\Microsoft Visual Studio .NET\EnterpriseFrameworks". To make our template appear in the new project dialog box, we will create a new file named CustomDistributedAppTemplateProjects.vsdir that looks like the following.

..\Projects\CustomDistributedAppTemplate\
   CustomDistributedAppTemplate.etp|
  {AE77B8D0-6BDC-11d2-B354-0000F81F0C06}|
  CustomDistributedAppTemplate|0|
  A Custom Distributed Application Template|
  {AE77B8D0-6BDC-11d2-B354-0000F81F0C06}|125|0|
  CustomDistributedAppTemplate

Each field in the above file is delimited by the character |. The above fields determine values for properties such as RelPathName, LocalizedName, SortPriority, Description, SuggestedBaseName, and so on.

Putting It All Together

Now that we have constructed the different parts of the application, let us test our enterprise template by going to File->New Project and selecting Other Projects->Enterprise Template Projects. In the New Project dialog box, you will find CustomDistributedAppTemplate listed in the Templates pane.

As you can see from the above screenshot, our custom template is listed in the New Project dialog box. From the above dialog box, you can just select CustomDistributedAppTemplate as the template and create a new project from the template. In the created project, you will see all of the building blocks that we added earlier.

Conclusion

In Part 3 of this article, we will see how to add custom help topics to our CustomDistributedAppTemplate so that the developers can easily find help on how to use the template. We will also take a look at how to customize the Visual Studio.NET development environment.

About the Author

Thiru has six years of experience in architecting, designing, developing and implementing applications using Object Oriented Application development methodologies. He also possesses a thorough understanding of software life cycle (design, development and testing).

He is an expert with ASP.NET, .NET Framework, Visual C#.NET, Visual Basic.NET, ADO.NET, XML Web Services and .NET Remoting and holds MCAD for .NET, MCSD and MCP certifications.

Thiru has authored numerous books and articles. He can be reached at thiruthangarathinam@yahoo.com.

# # #

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date