views:

152

answers:

2

I need to construct a Visual Studio project template that has a certain amount of intelligence. I've discovered a way to get Visual Studio to call my custom code upon creation of a new project from my template, the custom code displays a dialog box and gathers information from the user, then defines additional substitutions that the project template can use. All well and good.

This template was previously a collection of several very similar templates, which differed only in which interface was implemented by the main class. My goal is to condense this collection of templates into a single "smart template" which automatically implements the correct interface depending on user input.

To do that, I need to modify the generated code at the time it is created. Visual Studio calls my custom wizard code after the new project is created, then I'd like to go into the newly-created C# code and add the Interface implementation programmatically. I'd like to add the " : IMyInterface" after the main class, then trigger IntelliSense to expand the implementation for me. This is the part I don't know how to do.

Can anyone give me some pointers on how to automate the imlementation of an interface using the Visual Studio object model?

A: 

If you can open the file itself and load it as text, you should be able to just put a placeholder in the place of the initial interface (say, #interface_placeholder#), then do a search/replace on that in the string, and add that to the project instead of the initial file. I think that should be possible, anyway. Does it make sense?

That makes sense, but it doesn;t answer the question. I'm already using a substitution string to alter the _name_ of the interface. The question deals with how, once I've inserted the correct INterface name, how do I get Intellisense to then implement that interface in the code for me? The alternative is leaving it to the user to do manually, which is not the ideal solution though it is workable. I want to leave the user with a project that will compile.
Tim Long
Ah, I see. I didn't understand that part! My mistake. This may require you to use a code-generation tool, or write some code-generation methods that can turn the interface into an object, then use the metadata to put the appropriate functions in. I'm not really sure how much work would be required for that, but I suspect you can look up some code-generation techniques on the net.
Hm, also just thought of this. What if you included default implementations of each interface type, and then wrote your own IWizard which selects the appropriate implementation at project-creation time?
A: 

I think the best solution that suits your need is to use GAT and GAX.

It requires a little bit of work to make it working well but It can definitely help you : http://msdn.microsoft.com/en-us/teamsystem/aa718948.aspx

PatriceVB