Subscribe and Follow

Macro In Visual Studio

Macro Used In Visual studio There are many tasks that we do in Visual Studio that are repetitive and which can be automated using macros...

Macro Used In Visual studio


There are many tasks that we do in Visual Studio that are repetitive and which can be automated using macros. One such example is attaching to process for debugging. Having the ability to debug an existing running process (Ex: Process of a .net console application exe) is a common requirement. The usual way would be using the Attach To Process window from Debug -> Attach To Process in Visual Studio. But this can become cumbersome and irritating if we have to do it again and again to test iterative changes. This is where macros come to our rescue.


 We want to debug from the second breakpoint by attaching to this process so, Now we start recording our macro in 5 simple steps –

 Click Record Temporary Macro from the Tool -> Macros menu as shown below:


Recording is started. Now perform the necessary actions to attach to the process as below:

Click Debug -> Attach to Process

In the popup below find your process and click Attach.

 Stop recording the macro using Tools -> Macros as below:

 Save the macro using Tools -> Macros as below:




 Upon saving, the macro will appear in the Macro Explorer. I have named it Attach To My Program.


 Lastly we can also place a shortcut to this macro on the Debug toolbar to make things even simpler.

 Go to Tools -> Customize -> Commands and under Toolbar dropdown select Debug as below:


 Hit the Add Command button and on the below popup select macros under Categories andAttachToMyProgram under commands:

 Now from under the Modify Selection rename the command as shown below:

Now the AttachToMyProgram shortcut show appear in the Debug toolbar as shown below:

6. Now close the console application and start again. We will again see the “I am started” message. Now simply hit the AttachToMyProcess shortcut on the Debug bar and press any key in the console application window. There you are! You are in the debug session and the second breakpoint is hit. Now you can easily attach to your process with a click of a button.

0 comments: