... .x+=:. s . .. .uW8***88e. x=~ z` ^% :8 .uef^" x=~ @88> dF d8*" `"8N. 88x. .e. .e. . :k .88 :d88E 88x. .e. .e. %8P .. .u . '88bu. .@8F .ucu.. %8L '8888X.x888:.x888 u .@8Ned8" u :888ooo . `888E '8888X.x888:.x888 . .@88i u .d88B :@8c '*88888bu @8E .@8""988 8N `8888 888X '888k us888u. .@^%8888" us888u. -*8888888 .udR88N 888E .z8k `8888 888X '888k .@88u ""%888> us888u. ="8888f8888r ^"*8888N '88> @8~ 98F 98 X888 888X 888X .@88 "8888" x88: `)8b. .@88 "8888" 8888 :888'888k 888E~?888L X888 888X 888X ''888E` '88% .@88 "8888" 4888>'88" beWE "888L ~88 X8E 98~ 8E X888 888X 888X 9888 9888 8888N=*8888 9888 9888 8888 9888 'Y" 888E 888E X888 888X 888X 888E ..dILr~` 9888 9888 4888> ' 888E 888E '88> 988 d88 X8 X888 888X 888X 9888 9888 %8" R88 9888 9888 8888 9888 888E 888E X888 888X 888X 888E '".-%88b 9888 9888 4888> 888E 888E %8N '88W@"%8ed*` .X888 888X. 888~ 9888 9888 @8Wou 9% 9888 9888 .8888Lu= 9888 888E 888E .X888 888X. 888~ 888E @ '888k 9888 9888 .d888L .+ 888E 888F %8b. `" `` `%88%``"*888Y" 9888 9888 .888888P` 9888 9888 ^%888* ?8888u../ 888E 888E `%88%``"*888Y" 8888 8F 8888 9888 9888 ^"8888*" .888N..888 `*8bu.. ..u@ `~ `" "888*""888" ` ^"F "888*""888" 'Y" "8888P' m888N= 888> `~ `" R888" '8 8888 "888*""888" "Y" `"888*"" ^"***%"` ^Y" ^Y' ^Y" ^Y' "P' `Y" 888 "" '8 888F ^Y" ^Y' "" J88" %k :88F @% "+:*%` :"
Friday, September 18, 2009
Visual Studio 2008 Macro Fun

Here are a few macros that I use, that I thought might be of use to others. They should be fairly easy to set up in your environment. I’m always excited to hear about new macros and plugins and other time-saving functionality for Visual Studio, so if you have any – please let me know!!

Misc Built-in Macros

Here are some basic macros that came with Visual Studio 2008 (and VS 2005) that are very useful and easily map to your favorite keyboard shortcut(s).

Macros.Samples.Accessibility.IncreaseTextEditorFontSize
Macros.Samples.Accessibility.DecreaseTextEditorFontSize
Macros.Samples.Accessibility.UpdateTextEditorFontSizeToMatchDisplayProperties
Macros.Samples.Utilities.TurnOnLineNumbers
Macros.Samples.Utilities.TurnOffLineNumbers
Macros.Samples.VSEditor.BeginningOfFunction
Macros.Samples.VSEditor.LineEmUp (Good for aligning variable assignments)
Macros.Samples.DevStudio6Editor.AutoCompleteFromFile


Format Source Code



I map F2 to the standard Edit.FormatDocument command and Ctrl+F2 to the FormatCSharp macro method.



Public Sub FormatCSharp()

Try
' Remove and sort using statements if PowerCommands is installed.
DTE.ExecuteCommand("Edit.RemoveAndSort")
Catch ex As Exception

End Try

Try
DTE.ExecuteCommand("Macros.Samples.VSEditor.FixLineEnds")
Catch ex As Exception
Exit Sub
End Try

DTE.ExecuteCommand("Edit.FormatDocument")

End Sub






Attach to IIS Worker Processes



I map Ctrl+P to this macro, replacing the default Print Current Document shortcut.



Sub MacroAttachToAllWebProcesses() 
Try
Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")
Dim dbgeng(3) As EnvDTE80.Engine

dbgeng(0) = trans.Engines.Item("T-SQL")
dbgeng(1) = trans.Engines.Item("T-SQL")
dbgeng(2) = trans.Engines.Item("Managed")

' Use . for local machine or type machine name
For Each theProcess As EnvDTE80.Process2 In dbg2.GetProcesses(trans, ".")
If theProcess.Name.Contains("aspnet_wp.exe") Or theProcess.Name.Contains("w3wp.exe") Then
theProcess.Attach2(dbgeng)
End If
Next

Catch ex As System.Exception
MsgBox(ex.Message)
End Try

End Sub


Solution Events



' Automatically close all documents when the solution is closed.
Private Sub SolutionEvents_BeforeClosing() Handles SolutionEvents.BeforeClosing
DTE.ExecuteCommand("Window.CloseAllDocuments")
End Sub


Build Events



' A project failed to compile, so cancel remaining and beep
Private Sub BuildEvents_OnBuildProjConfigDone(ByVal Project As String, ByVal ProjectConfig As String, ByVal Platform As String, ByVal SolutionConfig As String, ByVal Success As Boolean) Handles BuildEvents.OnBuildProjConfigDone
If Success = False Then
DTE.ExecuteCommand("Build.Cancel")
' System.Windows.Forms.MessageBox.Show("Build failed!")
Beep()
Threading.Thread.Sleep(500)
Beep()
Threading.Thread.Sleep(500)
Beep()
Threading.Thread.Sleep(500)
Beep()
End If
End Sub

' The build finished successfully
Private Sub BuildEvents_OnBuildDone(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildDone
If (Not failed) Then
' System.Windows.Forms.MessageBox.Show("Build is complete!")
Beep()
Threading.Thread.Sleep(250)
Beep()
End If
End Sub
Older Post Home Newer Post