Gary
Gary

Reputation: 1877

How can I set a file name using a variable in a Visual Studio project template

I have a VS 2013 project template with a item like below

<ProjectItem ReplaceParameters="true" TargetFileName="Target.xml">Target.xml</ProjectItem>

What I want is "Target.xml" to be MyProjectName.xml.

I know I can use variables inside the file but not in the name.

Thanks

G

Upvotes: 3

Views: 5930

Answers (2)

jlo-gmail
jlo-gmail

Reputation: 5038

The Microsoft documentation doesn't mention that you also have to modify the .proj file.

<Content Include="Target.html" />

change to

<Content Include="$projectname$.html" />

Also, in the .vstemplate file, the ReplaceParameters attribute doesn't need to be changed to "true" if you're just changing the filename.

Upvotes: 0

Matze
Matze

Reputation: 5508

Indeed, you can also use variables within the item template. For instance...

<ProjectItem 
    TargetFileName="$fileinputname$.xml" 
    ReplaceParameters="true" 
    ItemType="Content">Target.xml</ProjectItem>

...whereby fileinputname is the name as specified in the wizard (without extension). The safeprojectname parameter would give you the project name (not sure, if this can only be used in conjunction with a project template, rather than in an isolated item template).

This is the link to the Project and Item Templates documentation; might be of your interest: https://msdn.microsoft.com/en-us/library/ms247121.aspx

A list of available parameters can be found at: https://msdn.microsoft.com/en-us/library/eehb4faa.aspx

Upvotes: 6

Related Questions