[英]Get process id from DTE (EnvDte)
Is it possible to get the process id of a visual studio instance through the DTE mDte variable? 是否可以通过DTE mDte变量获取Visual Studio实例的进程ID? Refer to code below.
请参阅下面的代码。
private static DTE mDte;
public static void OpenVisualStudio()
{
Type visualStudioType = Type.GetTypeFromProgID("VisualStudio.DTE.10.0");
mDte = Activator.CreateInstance(visualStudioType) as DTE;
if (mDte != null)
{
mDte.MainWindow.Visible = true;
}
// get process id of visual studio instance through mDte
}
I have done as follows : 我做了如下:
public static int OpenVisualStudio()
{
var devenv = Process.Start("devenv.exe");
if (devenv == null)
{
return 0;
}
do
{
System.Threading.Thread.Sleep(2000);
mDte = GetDte(devenv.Id);
}
while (mDte == null);
return devenv.Id;
}
I got it from here: http://blogs.msdn.com/b/kirillosenkov/archive/2011/08/10/how-to-get-dte-from-visual-studio-process-id.aspx 我从这里得到的: http : //blogs.msdn.com/b/kirillosenkov/archive/2011/08/10/how-to-get-dte-from-visual-studio-process-id.aspx
It solves my problem for now... 它现在解决了我的问题...
DTE
对象具有Debugger
属性,该属性具有CurrentProcess
属性,该属性具有ProcessID
属性。
int processId = dte.Debugger.CurrentProcess.ProcessID;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.