ProjectItem is an optional child of Project.
The TargetFileName attribute can be used to create a directory structure different from the directory structure in the template .zip file. For example, if the file MyFile.vb exists in the root of the template .zip file, but you want the file to be placed in a directory named CustomFiles in all projects created from the template, you would use the following XML:
<ProjectItem TargetFileName="CustomFiles\MyFile.vb">MyFile.vb</ProjectItem>
The TargetFileName attribute can also be used to rename files that contain international characters in their filenames. For example, a template .zip file cannot contain file names with Unicode characters, so the file must be renamed before it can be compressed into a .zip file. The TargetFileName attribute can be used to set the file name back to the original Unicode file name.
The TargetFileName attribute can also be used to rename files with parameters. The following procedure explains how to rename the file MyFile.vb, which exists in the root directory of the template .zip file, to a file name based on the project name.
To rename files with parameters
-
Use the following XML in the .vstemplate file:
<ProjectItem TargetFileName="$safeprojectname$.vb">MyFile.vb</ProjectItem>
-
Open the project file (.vbproj for a Visual Basic project) in a text editor or Visual Studio. For more information on editing project files in vsprvs, see How To: Edit Project Files.
-
Locate the line in the project file that looks similar to the following XML:
<Compile Include="MyFile.vb">
-
Replace the line of code with the following XML:
<Compile Include="$safeprojectname$.vb">
When a project is created from this template, the file name will be based on the name the user entered in the New Project dialog box, with all unsafe characters and spaces removed. For more information, see Template Parameters.