当我做:
// 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 的引用。该链接表明可以做到这一点。结果,我尝试了类似的方法:
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))
有更多链接显示如何执行我正在寻找的内容,但由于某种原因,我无法使其工作。以下是一些链接: