VSTemplate TargetFolderName with parameters

1.8k views Asked by At

I am trying to create ItemTemplate which will be similar to MVC's Area. Anyway, I am unable to create a Folder in TemplateContent that will have a TargetFolderName with parameter. Here is a simplified example of my TemplateContent section:

<TemplateContent>
    <Folder Name="Area" TargetFolderName="$AreaName$">
        <ProjectItem ReplaceParameters="true" TargetFileName="$AreaName$Controller.cs">Controller.cs</ProjectItem>
    </Folder>
</TemplateContent>

Even though MSDN states that TargetFolderName is

useful for using parameter replacement to create a folder name or naming a folder with an international string that cannot be used directly in the .zip file.

Despite that, I was unable to make this work.

Expected result for input 'TestArea':

TestArea
   |__ TestAreaController.cs

Actual result:

$AreaName$
   |__ TestAreaController.cs

Can someone help?

Thanks in advance.

2

There are 2 answers

0
Ivan Peric On BEST ANSWER

Just found a workaround here:

Can I create a new folder with a Visual Studio Item Template

So this is how I solved it:

<TemplateContent>
    <ProjectItem ReplaceParameters="true" TargetFileName="$AreaName$\$AreaName$Controller.cs">Controller.cs</ProjectItem>
</TemplateContent>
0
AdamTups On

I had the same problem as you but your solution didn't quite solve my problem so I have come up with a more comprehensive solution (which works for Visual Studio 2015).

You need to make the changes you have done to the template file:

<TemplateContent>
    <Folder Name="Area" TargetFolderName="$AreaName$">
    <ProjectItem ReplaceParameters="true" TargetFileName="$AreaName$Controller.cs">Controller.cs</ProjectItem>
    </Folder>
</TemplateContent>

and on top of that make some changes to .csproj (project) file and in the include statements ("Compile Include" and "None Include" tags) make sure that the file path for the files you are putting in the new folder is the same as the new file path you have specified in the template file.