views:

52

answers:

2

We have a Visual Studio Wizard written using the DTE environment to automatically generate code, templates, etc.. based off some custom database stuff. Right now it brings up a few dialogs, collects information, and then uses the EnvDTE class to generate the code and format it.

Given that I have the information collected from the dialogs available, is there a way to invoke devenv and have it run the wizard to automatically generate the code?

A: 

You certainly can run Visual Studio from command line. You can even make it execute a command (devenv /Command ...), but it still means bootstrapping the entire Visual Studio. It is hardly suitable for running in batch mode if this is what you intend.

What you can do instead is use CodeDom for code generation. It does not relay on EnvDTE or anything else from Visual Studio to generate the code. In my code generator I also started from using Visual Studio Automation, but when it came to batch builds, I had to redo it using CodeDom instead

mfeingold
I will have to look into /Command option. Bootstrapping the entire Visual Studio is fine, I care more about automating the process than anything. I ideally would like it to be part of the build itself (build produces code that then gets built). I wouldn't mind rewriting it for CodeDom but I only have 2 days allocated to this whole project, and rewriting this amount of code generation would take a week.
esac
Update: looked at all of the command line options, don't see anything for executing a wizard, so I would need to move the whole wizard to a command line version which doesn't seem to work with EnvDTE.
esac
With all my experience dealing with VS Integration - Packages, CodeGeneration, Editors, etc. working with Automation still gives me heartburn. It is heavy unstable and documented even worse than the rest of it. IMHO rewriting it in CodeDom would be more predictable than the path you have in mind. But of course it all depends on the amount of code generation code you have to cut through
mfeingold
A: 

The answer to this was visual studio automation using DTE2 interface. For example, I created a new instance of Visual Studio with

Type t = Type.GetTypeFromProgID("VisualStudio.DTE.9.0", true);
object obj = System.Activator.CreateInstance(t, true);
m_DTEInstance = obj as DTE2;

Then you can do things such as creating a new solution:

Solution2 solution = (Solution2)m_DTEInstance.Solution;
solution.Create(OutputDirectory, Namespace + ".sln");
esac