Template Parameters
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Template Parameters 

All templates support parameter substitution to enable replacement of key parameters, such as class names and namespaces, when the template is instantiated. These parameters are replaced by the template wizard that runs in the background when a user clicks OK on the New Project and Add New Item dialog boxes.

Declaring and Enabling Template Parameters

Template parameters are declared in the format $parameter$. For example:

  • $safeprojectname$

  • $safeclassname$

  • $guid1$

  • $guid5$

To enable parameter substitution in templates

  1. In the .vstemplate file of the template, locate the ProjectItem element that corresponds to the item that you want to enable parameter replacement for.

  2. Set the ReplaceParameters attribute of the ProjectItem element to true.

  3. In the code file for the project item, include parameters in code where appropriate. For example, the following parameter specifies that the safe project name be used for the namespace in a file:

    namespace $safeprojectname$

Reserved Template Parameters

The following table lists the reserved template parameters that can be used by any template.


Template parameters are case-sensitive.

Parameter Description


Current version of the common language runtime (CLR).

GUID [1-10]

A GUID used to replace the project GUID in a project file. You can specify up to 10 unique GUIDs (for example, guid1).


The name provided by the user in the Add New Item dialog box.


The current computer name (for example, Computer01).


The name provided by the user in the New Project dialog box.


The registry key value from HKLM\Software\Microsoft\Windows NT\CurrentVersion\RegisteredOrganization.


The root namespace of the current project. This parameter is used to replace the namespace in an item being added to a project.


The name provided by the user in the Add New Item dialog box, with all unsafe characters and spaces removed.


The name provided by the user in the New Project dialog box, with all unsafe characters and spaces removed.


The current time in the format DD/MM/YYYY 00:00:00.


The current user domain.


The current user name.


The current year in the format YYYY.

Custom Template Parameters

In addition to the reserved template parameters that are automatically used during parameter replacement, you can specify your own template parameters and values. For more information, see How to: Pass Custom Parameters to Templates.

Example: Replacing Files Names

You can specify variable file names for project items using a parameter with the TargetFileName attribute. For example, you could specify that the .exe file use the project name, specified by $projectname$, as the file name.


Example: Using the Project Name for the Namespace Name

To use the project name for the namespace in a Visual C# class file, Class1.cs, use the following syntax:

#region Using directives

using System;
using System.Collections.Generic;
using System.Text;


namespace $safeprojectname$
    public class Class1
            public Class1()


In the .vstemplate file for the project template, include the following XML when referencing the file Class1.cs:

    <ProjectItem ReplaceParameters="true">

See Also

© 2015 Microsoft