[原创]使用Visual Studio Macro调试VSPackage项目
作者:互联网
最近在做一个Visual Studio 2008的扩展项目,主要是基于VSPackage进行开发,在使用Team Foundation进行源代码管理时发现如下问题:
解决方案中有一个使用Visual Studio Integration Package向导创建出来的项目,该项目调式时通过执行外部应用程序(如:"D:\Develop Tools\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe /ranu /rootsuffix Exp”)启动Microsoft Visual Studio - Experimental Hive,但是项目组成员Visual Studio 2008的安装路径都不相同,在调试时如果修改外部程序路径就会签出该项目文件,并且由于需要签出的是项目文件还不能使用去掉只读属性在本地修改的方式。
尝试在外部程序中使用保存Visual Studio 2008安装路径的环境变量不成功后,又尝试添加一个控制台项目然后通过Process.Start()方式启动一个Visual Studio进程,使用新建进程的问题在于无法自动附加进程进行调试,最后决定使用Visual Studio Marco通过Visual Studio 2008安装时设置的VS90COMNTOOLS环境变量获取安装目录,然后通过Process.Start()启动devenv进程,然后遍历本地计算机中所有进程找到该进程然后调用EnvDTE附加进程。
Macro的实现代码如下:
1: Imports System
2: Imports EnvDTE
3: Imports EnvDTE80
4: Imports EnvDTE90
5: Imports System.Diagnostics
6:
7: Public Module VSXDebugger
8:
9: Sub VSXDebugger()
10:
11: Try
12: Dim comnTools As String = Environment.GetEnvironmentVariable("VS90COMNTOOLS")
13:
14: Dim comnDir As String = System.IO.Path.GetDirectoryName(comnTools)
15:
16: Dim idePath As String = System.IO.Path.Combine(comnDir, "..\\IDE\\devenv.exe")
17:
18: idePath = System.IO.Path.GetFullPath(idePath)
19:
20: Dim proc As System.Diagnostics.Process = New System.Diagnostics.Process()
21:
22: proc.StartInfo = New System.Diagnostics.ProcessStartInfo(idePath, "/ranu /rootsuffix Exp")
23:
24: proc.Start()
25:
26: Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
27:
28: Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")
29:
30: Dim dbgeng(1) As EnvDTE80.Engine
31:
32: dbgeng(0) = trans.Engines.Item("Managed")
33:
34: Dim procTmp As EnvDTE80.Process2
35: For Each p In dbg2.GetProcesses(trans, Environment.MachineName)
36: procTmp = CType(p, EnvDTE80.Process2)
37: If procTmp.ProcessID = proc.Id Then
38: procTmp.Attach2(dbgeng)
39: Exit For
40: End If
41: Next
42:
43: Catch ex As System.Exception
44:
45: MsgBox(ex.Message)
46:
47: End Try
48:
49: End Sub
50:
51: End Module
转载于:https://www.cnblogs.com/pagsun/archive/2009/07/20/1526778.html
标签:Dim,Macro,EnvDTE80,Visual,System,VSPackage,Studio,Imports 来源: https://blog.csdn.net/weixin_30455365/article/details/99190637