我在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