Wednesday, November 14, 2012

Automate Visual Studio from Linqpad

I really love LinqPad. Not that it doesn't have features I want, but that it just handles so many things in a convienent way. Starting with the whopping 6mb size. Enough about that. I was just sure that there was a way to reach into Visual Studio from another process and do stuff. I had forgotten how. I had forgotten that I had even succeeded before. I tried to find a way again. This is the rather short magic that was needed.
var dte = (EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE");
and a simple ask/command sample in linqpad
    const string SolutionExplorerWindow="{3AE79031-E1BC-11D0-8F78-00A0C9110057}";
 const string SolutionFolder="{66A26720-8FB5-11D2-AA7E-00C04F688DDE}";
 var dte = (EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE");
 //var uih=dte.ActiveWindow.Object as UIHierarchy;

No comments:

Post a Comment