Attach to debugger thru Command Line

  • Thread starter Thread starter Trevor Benedict
  • Start date Start date
T

Trevor Benedict

Is there a way to attach a running Instance of Visual Studo 2008
(devenv.exe) to multiple instance of the devlopment web server
(WebDev.WebServer) for example.

I am trying to get a power shell script that can kill, start and attach this
process automatically. The script below is to kill and start the WebDev
Server. I would like to attach these 3 processes to a Running instance of
Visual Studio.

@echo off
set vDir=C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\
set pDir=C:\Trevor\PP\

powershell -command "Get-Process | Where { $_.Name -Eq 'WebDev.WebServer' }
| Kill"
start %vDir%WebDev.WebServer /port:2222 /path:"%pDir%WebServices" /vpath:"/"
start %vDir%WebDev.WebServer /port:2223 /path:"%pDir%Security" /vpath:"/"
start %vDir%WebDev.WebServer /port:2852 /path:"%pDir%WebUI.Application"
/vpath:"/"
sleep 2
exit


You may wonder why not run it from Visual Studio to save the trouble. most
times I don't need the debugger, just compile and go, when I need to, I can
attach to it using a batch file if I have to. TIA.

Regards

Trevor.
 
Nevermind, I found a way using the EnvDTE80 Namespace.

If anyone else wants to do this, you can create a Macro, extract the code as
a Project and use comman line arguments to make it a generic utility.

Regards,

Trevor Benedict
 
This is the code if anyone is interested. Created a Console Application and
place in the main module. (Visual Studio 2008)

Option Strict Off

Option Explicit Off

Imports System

Imports EnvDTE

Imports EnvDTE80

Imports EnvDTE90

Imports System.Diagnostics

Imports System.Threading

Module modMain

Function AttachToProcess(ByVal processName As String, _

ByVal Timeout As Integer) As Boolean

Dim proc As EnvDTE.Process

Dim attached As Boolean

Dim DTE2 As EnvDTE80.DTE2

Try

DTE2 =
System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.9.0")

For Each proc In DTE2.Debugger.LocalProcesses

If (Right(proc.Name, Len(processName)).ToUpper = processName.ToUpper) Then

proc.Attach()

System.Threading.Thread.Sleep(Timeout)

attached = True

End If

Next

Catch Ex As Exception

Console.Write("Unable to Attach to Debugger : " & Ex.Message)

End Try

Return attached

End Function

Sub Main()

'to call w/ Command Line arguments follow this syntax

'AttachProcess <<ProcessName>> <<TimeOut [used when multiple instances of
the same process are running]>>

'AttachProcess WebDev.WebServer.Exe 2000

Dim AppName As String = "WebDev.WebServer.EXE"

Dim TimeOut As Integer = 2000 '2 Seconds

Try

If Environment.GetCommandLineArgs().Length > 1 Then

AppName = Environment.GetCommandLineArgs(1)

End If



If Environment.GetCommandLineArgs().Length > 2 Then

If IsNumeric(Environment.GetCommandLineArgs(2)) Then

TimeOut = Environment.GetCommandLineArgs(2)

End If

End If

Environment.GetCommandLineArgs()

AttachToProcess(AppName, TimeOut) '"WebDev.WebServer.EXE"

Catch Ex As Exception

Console.Write("Unable to Attach to Debugger : " & Ex.Message)

End Try

End Sub

End Module


Regards,

Trevor Benedict
 
Back
Top