我在VS中使用这个宏,我将它连接到Visual Studio中的一个快捷键,它基本上做了什么适合你,使用调试器附加到w3wp.exe。由于我有类似的问题与自动附件不完全按我预期的方式工作。对我来说这是一种享受。我也不喜欢IE自动启动,因为我通常在Firefox中测试。所以这个宏不会触发我喜欢的IE自动启动。
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module AttachToWebServer
Public Sub AttachToWebServer()
Dim AspNetWp As String = "aspnet_wp.exe"
Dim W3WP As String = "w3wp.exe"
If Not (AttachToProcess(AspNetWp)) Then
If Not AttachToProcess(W3WP) Then
System.Windows.Forms.MessageBox.Show(String.Format("Process {0} or {1} Cannot Be Found", AspNetWp, W3WP), "Attach To Web Server Macro")
End If
End If
End Sub
Public Function AttachToProcess(ByVal ProcessName As String) As Boolean
Try
Dim ProcessFound As Boolean = False
Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")
Dim dbgeng(10) As EnvDTE80.Engine
Dim indexer As Integer = 0
For Each myEngine As Engine In trans.Engines
'Possible values here could be "T-SQL","Native","Managed","Workflow" "Managed/Native", "Script"
If myEngine.Name.Equals("Managed") Then
dbgeng(indexer) = myEngine
indexer += 1
End If
Next
Dim processes As EnvDTE.Processes = dbg2.GetProcesses(trans, "localhost")
For Each Process As EnvDTE80.Process2 In processes
If Process.Name.Contains(ProcessName) Then
Process.Attach2(dbgeng)
ProcessFound = True
End If
Next
Return ProcessFound
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Function
End Module
我是管理员 – bechbd 2009-06-01 16:38:28