当我这样做:连接到IDE的具体实例
// Get an instance of the currently running Visual Studio IDE.
EnvDTE80.DTE2 dte2;
dte2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.
GetActiveObject("VisualStudio.DTE.10.0");
var solution = dte2.Solution; // get solution
Console.WriteLine(solution.FullName); // prints the name of the solution where this code is written
我能够获得当前的IDE实例
我会想获得一个参考DTE2的一个不同的视觉工作室实例。 This link指出有可能这样做。因此,我已经试过类似:
Process p = new Process();
ProcessStartInfo ps = new ProcessStartInfo(@"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe");
p.StartInfo = ps;
p.Start(); // start a new instance of visual studio
var ROT = "!VisualStudio.DTE.10.0:" + p.Id;
// Get an instance of the NEW instance of Visual Studio IDE.
EnvDTE80.DTE2 dte2;
dte2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.
GetActiveObject(ROT);
如果我尝试,我得到异常:
无效类的字符串(从HRESULT异常:0x800401F3(CO_E_CLASSSTRING))
有更多的链接显示如何做我在找什么,但由于某种原因,我不能让它工作。下面是一些链接:
http://msdn.microsoft.com/en-us/library/6cefss65.aspx
http://msdn.microsoft.com/en-us/library/ms228755.aspx已经为我工作
有其他人注意到如何“GetActiveObject”并不总是返回VS的当前实例,而是当前实例,而不是当前打开的实例集合,该实例首先打开。 – 2015-01-13 12:03:20