views:

74

answers:

2

I'm currently using a "New Item" template of mine to create several classes in my project based on the Name entered. What I'd like to be able to do, is to also add some lines to an existing file in the project. Is there any way to do this? Is there any way to run some sort of script from within the .vstemplate file?

A: 

EDIT: Sorry, I misunderstood the question.

Original answer:
Well, the default templates are in 2 places:
\Program Files\Microsoft Visual Studio 8\Common7\IDE\ItemTemplatesCache\CSharp\1033
\Program Files\Microsoft Visual Studio 8\Common7\IDE\ItemTemplates\CSharp\1033

You can change the template contents for new classes and new forms in there at your leisure... Not sure where user created templates are saved, but there's no reason you couldn't do the same thing to those (to my knowledge.)

Jacob G
User-created templates are stored in the location specified under Tools->Options->Projects and Solutions->General->Visual Studio user item templates location, but I've gotten that working already, that's not what I'm having a problem with.
Dov
+1  A: 

For a vanilla item template in Visual Studio there is no way to achieve this. Item and Project templates just allow you to add new files to a project and allow for customizations of those files. But it's not possible to use them to change existing files.

You may be able to achieve what you're looking for though with a template wizard. This allows for the execution of arbitrary code during the processing of a template. You should be able to modify the existing files to your delight with this.

Tutorial Link:

JaredPar
I just watched the video, and found it very helpful - a wizard will definitely allow me to do what I want. My biggest question remaining, though, is if there's some way to avoid installing the DLL for the wizard into the GAC. Is there some way to just embed it in the template's ZIP file?
Dov
@Dov, I'm not sure about that one. I would try deploying in the GAC, verifying it worked and then uninstall from the GAC, deploy locally and see what happens.
JaredPar