If you take a look at my post a few months ago about my own development environment, maybe you didn’t notice that I posted a link to a macro. This macro I’ve created myself to help me build SharePoint solutions faster than normally we do, rather than we do an “Attach to Process” on the menu and search which w3wp, or even worse, by attaching it to all w3wp which we don’t need.
So, in the code below, I put 2 functions, AttachW3WP(string AppPoolName) and AttachProcess(string ProcessName). Same way, you can create another function, call that function to attach to particular w3wp process with specific Application Pool Name.
This should work with IIS 7.0 above, as IIS 6.0 (or even IIS 5.1) I’ve never tested it out.
- Imports System
- Imports EnvDTE
- Imports EnvDTE80
- Imports EnvDTE90
- Imports EnvDTE90a
- Imports EnvDTE100
- Imports System.Diagnostics
- Imports System.Linq
- Imports System.ComponentModel
- Imports System.Collections
- Imports System.Collections.Generic
- Imports System.Management
- Public Module RdzMacros
- Dim DebugPanel As String = "Debug"
- Dim Ow As OutputWindow = DTE.ToolWindows.OutputWindow
- Dim Owp As OutputWindowPane
- Dim SetName As String = "ApplicationPoolName"
- Dim Titl As String = "AttachW3WP"
- Private Sub PanelInit()
- Try
- Owp = Ow.OutputWindowPanes(DebugPanel)
- Catch ex As Exception
- If Owp Is Nothing Then
- Owp = Ow.OutputWindowPanes.Add(DebugPanel)
- End If
- End Try
- End Sub
- Private Function GetAppPoolName() As String
- Dim sRet As String = ""
- Try
- sRet = DTE.Solution.Globals(SetName)
- Catch ex As Exception
- End Try
- Return sRet
- End Function
- Private Sub AttachW3WP(ByVal AppPoolName As String)
- PanelInit()
- Dim attached As Boolean = False
- Dim proc As EnvDTE.Process
- Dim ProcessName As String = "w3wp.exe"
- Dim PID As Integer = 0
- Dim CmdLine As String = AppPoolName 'GetAppPoolName()
- If String.IsNullOrEmpty(CmdLine) Then
- MsgBox("Set Application Pool Name first via 'SetApplicationPoolName' macro.", MsgBoxStyle.Critical, Titl)
- Exit Sub
- End If
- Owp.OutputString(String.Format("Search for IIS Worker Processes with AppPool '{0}'...", CmdLine))
- Dim wmiQuery As String = "select CommandLine,ProcessID from Win32_Process where Name='" + ProcessName + "'"
- Dim searcher As ManagementObjectSearcher = New ManagementObjectSearcher(wmiQuery)
- Dim retObjectCollection As ManagementObjectCollection = searcher.Get
- For Each retObject As ManagementObject In retObjectCollection
- If retObject("CommandLine").ToString().ToLower().Contains("\" + CmdLine.ToLower() + "\") = True Then
- PID = Convert.ToInt32(retObject("ProcessID").ToString())
- Owp.OutputString(String.Format("Found the ProcessID: {0}...", PID.ToString))
- Exit For
- End If
- Next
- If PID > 0 Then
- For Each proc In DTE.Debugger.LocalProcesses
- If proc.ProcessID = PID Then
- proc.Attach()
- attached = True
- Exit For
- End If
- Next
- End If
- If Not attached Then
- MsgBox("w3wp.exe with Argument '" + CmdLine + "' is not running!", MsgBoxStyle.Exclamation, "MiKrosok Pisual Studio 2010")
- Else
- Owp.OutputString(String.Format("ProcessID {0} already attached to VS debugger!", PID.ToString))
- Owp.Activate()
- End If
- End Sub
- Private Sub AttachProcess(ByVal ProcessName As String)
- PanelInit()
- Dim attached As Boolean = False
- Dim proc As EnvDTE.Process
- For Each proc In DTE.Debugger.LocalProcesses
- If proc.Name.ToLower().Contains(ProcessName.ToLower()) Then
- proc.Attach()
- attached = True
- Exit For
- End If
- Next
- If Not attached Then
- MsgBox("'" + ProcessName + "' is not running!", MsgBoxStyle.Exclamation, "MiKrosok Pisual Studio 2010")
- Else
- Owp.OutputString(String.Format("ProcessName {0} already attached to VS debugger!", ProcessName))
- Owp.Activate()
- End If
- End Sub
- Public Sub AttachOWSTimer()
- AttachProcess("owstimer.exe")
- End Sub
- Public Sub AttachOSCAR()
- AttachW3WP("SharePoint - 80")
- End Sub
- Public Sub AttachK2WorklistService()
- AttachW3WP("K2WorklistService")
- End Sub
- Public Sub AttachCommonWorkflowServices()
- AttachW3WP("CommonWorkflowServices")
- End Sub
- Public Sub AttachEIS()
- AttachW3WP("SharePoint - 80 - EIS")
- End Sub
- End Module
Hope it helps you.
Tidak ada komentar:
Posting Komentar
[give me your ideas, hopes, comments and compliments below...]
[aaand...... +1 if you need to....]