Run batch script before Debugging

南楼画角 提交于 2019-12-03 06:41:20
Reddog

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

dotalchemy
if $(ConfigurationName) == Debug mkdir c:\mydir

You should check out... How to run Visual Studio post-build events for debug build only

To run script before debugging with "Pre-Build Events":

Add your command line in the "Properties" of your projet > "Build Events":

cmd /c i:\foo.bat

A good example here => https://stackoverflow.com/a/57570301/2736742

So, you have a .bat file that you want to run via the pre-build event? Try to specify full path to your batch file in the pre-build event command e.g.

cmd /c C:\Path\to\foo.bat

or

cmd C:\windows\system32\cmd.exe /c C:\Path\to\foo.bat
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!