Is there a way to write an application that can connect to a running instance of Visual Studio and issue commands to it? For example, could I write a WPF app with a button that, when clicked, issues a "Build.BuildSolution" command to an already-open instance of Visual Studio, causing it to start a build?
I'm sure I could use SendKeys to send Ctrl+Shift+B, but I want to know if there's a way to write to an actual API to automate Visual Studio, and invoke commands by name.
Here's a C# program that connects to a running Visual Studio and issues a Build command. The
DTE.9
part means "Visual Studio 2008" - useDTE.8
for VS 2005, orDTE.10
for VS 2010.(The nonsense with STAThread and MessageFilter is "due to threading contention issues between external multi-threaded applications and Visual Studio", whatever that means. Pasting in the code from http://msdn.microsoft.com/en-us/library/ms228772.aspx makes it work.)
If you are just trying to automate builds/packaging of your apps, you should look into MSBuild -- it is Microsoft's build engine that lets you script automation of most of the functions of Visual Studio.