Saturday, October 4, 2008

Improve your visual studio experience and productivity

A quicker way to do -> Solution Explorer, Select Project, RightClick, Debug, Start new Instance.



I just couldn't find a shortcut key for doing this automatically. (Except F5 which actually builds all selected projects from Configuration Manager).



On a large scale solution with tens of projects, only selecting the current project in which you currently code, and doing the right click thingie, it's a pain in the ... you know better. :)



Searching the net, couldn't find much info except this excellent post: http://www.chinhdo.com/20070920/top-11-visual-studio-2005-ide-tips-and-tricks-to-make-you-a-more-productive-developer/



This one gave me the idea of implementing a macro for doing this automatically.



Go to: Tools -> Macros -> Macro Explorer.


Right click MyMacros, add a new macro and go to edit mode:
Write these lines:
--------------------------
Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Public Module RecordingModule

Sub StartDebuggingOnSelectedProject()


If (IsNothing(DTE.ActiveDocument)) Then
MsgBox("Open a document from project desired to start debug on first.", MsgBoxStyle.OkOnly, "No active document found.")
Else
If (MsgBox("Start debugging on" + DTE.ActiveDocument.ProjectItem.ContainingProject.Name, MsgBoxStyle.YesNo, "Debug?") = MsgBoxResult.Yes) Then
DTE.ExecuteCommand("ClassViewContextMenus.ClassViewProject.Debug.Startnewinstance")
End If
End If

End Sub

End Module
-----------
I only wish Macros were in C# and not VB. :P

Save it, rename it, and go to: Tools-Options-Environment-Keyboard.

On "show commands containing" type the name of your macro until the one you've created appears.
Then, assign a shortcut for it, like CTRL ALT SHIFT F5 or whatever you want, and you've saved yourself enough time of right clicking a menu and choosing some second menu item (which sometimes turns out to be a mistaken click.) :)

Test it by opening a file from the desired project and hitting the keystrokes. You can improve the code, as you need.

Happy coding.

No comments: