3

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

Matze
  • 5,100
  • 6
  • 46
  • 69
Gary
  • 1,847
  • 2
  • 14
  • 22

2 Answers2

6

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

Matze
  • 5,100
  • 6
  • 46
  • 69
  • it seems TargetFileName property does not work properly, when it is set VS is not able to copy the file. i tried it for a C# project template wiht VS 2015. – tutalia Jun 19 '17 at 07:26
  • @tutalia I updated the links to the documentation; since the content relates to Visual Studio 2015 and earlier versions, it may have changed for Visual Studio 2017, but I am not sure... The parameters might be case-sensitive. – Matze Jun 19 '17 at 07:35
  • 1
    for future readers, if the file is referenced in the proj file, don't forget to change the references inside the proj file as well. (ie ) – Mario Sep 28 '20 at 05:06
0

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.

jlo-gmail
  • 4,453
  • 3
  • 37
  • 64