Creating an Application Development Framework Using Enterprise Templates, Part 2, Page 2
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.
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>