Search code examples
c#visual-studiovisual-studio-templates

VSTemplate TargetFolderName with parameters


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.


Solution

  • 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>