I want to run a batch script every time before starting program for debugging.
For the build events, such functionality is realized using pre-build event, post-build event.
For actual debugging, I could not find any pre-Debug, post-Debug events.
How to realize this scenario?
I am using VS2008, .net framework 3.5, c# application.
I am opposed to idea of creating some extra lines of code within the application that would fire-up external batch file.
By adding pause command: One way to debug batch file is by executing the pause command or operation and halting the executing program if any kind of error is found or occurred then a developer can easily fix the issue by restarting the process.
It'll run your batch file in invisible/hidden mode. Solution-2: If at all possible, modify the batch file to run whatever program with the start command. By default, start returns immediately without waiting for the program to exit, so the batch file will continue to run and, presumably, exit immediately.
The debugger allows you to "single-step" through a batch file line by line, with the file displayed in a popup window as it executes. You can execute or skip the current line, continue execution with the debugger turned off, view the fully-expanded version of the command line, or exit the batch file.
I realise you wished to avoid additional code, but in your Main
function you could use Debugger.IsAttached()
to kick off your work for you.
For example:
if (Debugger.IsAttached)
{
System.Diagnostics.Process.Start(@"C:\myBatchFile.bat");
}
You can use a VS macro.
I had the same issue and this is the best I came with so far
Dim MustUpdateDB As Boolean
Private Sub DebuggerEvents_OnEnterRunMode(ByVal Reason As EnvDTE.dbgEventReason) Handles DebuggerEvents.OnEnterRunMode
If (MustUpdateDB) Then
MsgBox("Start debug operation", MsgBoxStyle.OkOnly, "TITLE")
REM DO WHATEVER COMMAND HERE
REM System.Diagnostics.Process.Start("C:\listfiles.bat")
MustUpdateDB = False
End If
End Sub
Private Sub BuildEvents_OnBuildDone(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildDone
MsgBox("Build Done", MsgBoxStyle.OkOnly, "Title")
MustUpdateDB = True
End Sub
There is a pretty good explanation on how to add event handlers to a macro here
The only issue I have so far is to figure out how to get the currently debugged application active directory
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With