Macros in .NET
This article explains how we can you Macros in Visual Studio .NET. Explanation with example
Macros in VS.NET
Macros in VS.NET
Have you ever used Macros in any other languages. We are repeatedly doing the same thing with the visualStudio. Analysis on a random sample of .net developers working on VS.NET reveals that around 20-40 % of time, they are doing same things, like create a file, try catch block or even setting the properties.
So why should one develop all routine jobs into macros and run.....interesting???
Macros are only one of the extensibility tools provided by Visual Studio.NET, and the interesting thing is we can write macro coding in .NET languages.So we have the full access to all Class libraries.
So shall we try some samples.
Select Tools > Macros > Record Temporary Macro from the Visual Studio.NET menu.
Type in the appropriate keystrokes, which will be recorded.
Click the stop button on the floating macro toolbar once you're finished.
You can now play the macro back using the menu or the convenience hotkey Ctrl-Shift-P.
To view the code for a recorded macro, select Select Tool > Macros > Macro Explorer. This window (shown below) shows a tree of macro modules, and the macros they contain. Each macro corresponds to a Visual Basic .NET subroutine
Here is the code to insert try...catch....finally block
Sub TryCatchFinally
with DTE.ActiveDocument.Selection
.Text = "try"
.NewLine()
.Text = "{"
.NewLine(10)
.Text = "}"
.NewLine()
.Text = "catch(Exception ex)"
.NewLine()
.Text = "{"
.NewLine()
.Text = "throw ex;"
.NewLine()
.Text = "}"
end with
End Sub
Hi,
It's good to see .