Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have successfully created (and manually edited) an Item Template that will add a number of files in one 'shot'. I want these files to all be created under a folder that should be created at the same time.

In Project Template .vstemplate files I can specify a Folder element, but the schema does not allow one in the Item Template.

Any know if this is possible or do I have to start looking at extending the IDE also?

like image 411
Chris Arnold Avatar asked Oct 01 '09 15:10

Chris Arnold


People also ask

Can you make a folder a template?

From within the folder click on the folder or the drop down arrow beside it. Click the "Save as Template" button to save this folder structure as a folder template.

Where are Visual Studio templates stored?

By default, templates installed with Visual Studio are located in: %ProgramFiles(x86)%\Microsoft Visual Studio\2019\<edition>\Common7\IDE\ProjectTemplates\<Language>\<Locale ID> %ProgramFiles(x86)%\Microsoft Visual Studio\2019\<edition>\Common7\IDE\ItemTemplates\<Language>\<Locale ID>

How do I create a folder and code in Visual Studio?

Adding folders#The File > Add Folder to Workspace command brings up an Open Folder dialog to select the new folder. Once a root folder is added, the Explorer will show the new folder as a root in the File Explorer. You can right-click on any of the root folders and use the context menu to add or remove folders.


1 Answers

I figured it out! You just need to edit the TargetFileName attribute of the ProjectItem element and suggest a fullpath...

<ProjectItem SubType="" TargetFileName="$fileinputname$\$fileinputname$.txt" ReplaceParameters="true">template.txt</ProjectItem>

In the above example if the user names the new item 'dog' VS will create a dog folder and copy the template.txt file as dog.txt into it.

like image 60
Chris Arnold Avatar answered Nov 16 '22 01:11

Chris Arnold