VS 2010 beta 2 : Macro to search Google using IE for "C#" + Selected Editor Text






4.60/5 (4 votes)
In response to this thread on the Lounge by Hans Dietrich : "Google Search from within Visual Studio" : [^] : I tried some of the macros linked to in comments on that thread in VS 2010 beta 2 with no success.I did find a sample on the net using 'Process.Start' which will open an external...
In response to this thread on the Lounge by Hans Dietrich : "Google Search from within Visual Studio" : [^] : I tried some of the macros linked to in comments on that thread in VS 2010 beta 2 with no success.
I did find a sample on the net using 'Process.Start' which will open an external window for searching, that I was able to modify into a usable macro module :
Option Strict Off Option Explicit Off Imports System Imports EnvDTE Imports EnvDTE80 Imports EnvDTE90 Imports EnvDTE100 Imports System.Diagnostics Public Module Module1 Sub SearchGoogle() Diagnostics.Process.Start("IExplore.exe","http://www.google.com/search?sourceid=navclient&ie=UTF-8&q=c%23+" & DTE.ActiveDocument.Selection.Text) End Sub End ModuleYou'll need to do the "usual thing" to add a new Macro, paste in the above code, build it, save it, then go to Tools/Options/Environment/Keyboard and set a keyboard shortcut for it. For a nice example of a VS Macro for VS 2008 (I haven't tried this one in VS 2010 beta 2) see : Invoke "Google from within VS 2008" By Ashish Sheth [^] ideas to improve : 1. add a test for a null selection : i.e., : DTE.ActiveDocument.Selection.Text == "" ... or similar when the Macro is invoked. Test if DTE.ActiveDocument.Selection == null ? 2. figure out how to open the window internally rather than using Process.Start : give the user the option of opening internal to VS 2010 or external. 3. figure out how : if IE is already running : to make the new IE window open as a new "tab" in the current IE "session" window. 4. ideally : put up a menu, so the user can choose between searching Google, MSDN, PInvoke, etc. as in Ashish Sheth's article referenced above. 5. make the browser invocation "flavour free" : so that that current browser, whatever that is, IE, Firefox, etc., is opened. Other resources : Came across a useful custom Google search page for MSDN : [^]