2 out of 8 rated this helpful - Rate this topic

How to: Pass Custom Parameters to Templates 

You can use the CustomParameter element in your .vstemplate file to add new parameters to a template. For a complete list of template parameters, see Template Parameters.

To add a custom parameter

  1. Locate the TemplateContent element in the .vstemplate file for the template.

  2. Add a CustomParameters element and one or more CustomParameter child elements as children of the TemplateContent element. For example:

    <TemplateContent>
        ...
        <CustomParameters>
            <CustomParameter Name="$MyParameter1$" Value="MyValue2"/>
            <CustomParameter Name="$MyParameter2$" Value="MyValue2">
        </CustomParameters>
    </TemplateContent>
    
  3. Use the parameter in one or more of the code files in the template. For example:

    string Value1 = "$MyParameter1"
    string Value2 = "$MyParameter2"
    

    When a project is created from the template, the values set by the Value attributes of the CustomParameter elements corresponding to the parameters will replace the parameters in the code files.

See Also

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Now information about visibility scope
If I define custom parameter in multi project template this parameter is not accessible in sub projects' templates.$0 $0 $0tfl - 29 06 10]

Hi - and thanks for your post. You should post questions like this to the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:$0 Visual Studio : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&amp;$0 SQL Server : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.sqlserver%2C&amp;$0 .NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework$0 PowerShell : http://groups.google.com/group/microsoft.public.windows.powershell/topics?pli=1$0 All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&amp;$0 $0 $0$0 $0 $0Note: While it's helpful to post links for where to ask questions...I don't think it was a question. Rather, it's a note about what doesn't work, and perhaps a request to make it work. This would have saved me a lot of time if I knew this ahead of time. The multi-project template just doesn't quite work the way you would expect for it to be truly useful. Personally, having this comment here is very useful, and the point the original author made should be incorporated into the documentation so people don't waste days trying to implement something that is never going to work.$0

(Sorry about the formatting - All I did was click edit, added text to the bottom and hit submit.)
Typo in paragraph 3 above
The code should look like:

string Value1 = "$MyParameter1$"
string Value2 = "$MyParameter2$"

end tag required
end tag required for <CustomParameter> tag

<CustomParameters>
<CustomParameter Name="$MyParameter1$" Value="MyValue2"/>
<CustomParameter Name="$MyParameter2$" Value="MyValue2"/>
</CustomParameters>
Advertisement