Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - Attach to debugger thru Command Line

Reply
 
Old 03-12-2009   #1 (permalink)
Trevor Benedict


 
 

Attach to debugger thru Command Line

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.



My System SpecsSystem Spec
Old 03-12-2009   #2 (permalink)
Trevor Benedict


 
 

Re: Attach to debugger thru Command Line

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

"Trevor Benedict" <trevornews@xxxxxx> wrote in message
news:uD%23XND3oJHA.5420@xxxxxx
Quote:

> 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.
>

My System SpecsSystem Spec
Old 03-13-2009   #3 (permalink)
Trevor Benedict


 
 

Re: Attach to debugger thru Command Line

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


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Running a command from inside a script, command line is corrupted PowerShell
command line Vista General
What is the command line command for unzipping files? Vista General
Command Line Ren (Rename) command broken? Vista General
XP command line Vista networking & sharing


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46