私がする時:
// 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のインスタンスを取得できます
ただし、別のVisualStudioインスタンスの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))
私が探していることを行う方法を示すリンクは他にもありますが、何らかの理由でそれを機能させることができません。リンクの一部を次に示します。