Question

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?

Was it helpful?

Solution

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");

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top