Tarun and I have started working on new Visual Studio extension, which we plan to release in couple of weeks after Christmas. One of the first thing I do as soon as we start the work on new tool/extension, is to gather all the features we have planned and build as many sample extensions as I can (each extension doing part of the functionality which is demo-able). This helps me to get the sense of complexity and also minimal code needed for a functionality to work. Another benefit is, we get the advantages and limitations of the implementation. This helps us to look for other alternatives if the PoC doesn’t fit our need or too complex to build in the given time frame.

As part of this new extension, we need to open a web page on click of a hyperlink. But we do not like it to be opened in the external browser, rather we wanted it to be opened within Visual Studio itself. What I thought as a complex functionality, turned out to be too simple. This is pretty easy to implement with only 3 lines of code.

Visual Studio SDK has IVsWebBrowsingService interface, which has Navigate method. This will open the URL within Visual Studio itself.

IVsWindowFrame ppFrame;
var service = Package.GetGlobalService(typeof (IVsWebBrowsingService)) as IVsWebBrowsingService;
service.Navigate("http://www.visualstudio.com/", 0, out ppFrame);

The second parameter in the Navigate method takes __VSWBNAVIGATEFLAGS enum. I am passing zero, which force creates browsing tab if doesn’t exist already and uses if it exists. If you want to create new tab every time the link is pressed you can use __VSWBNAVIGATEFLAGS.VSNWB_ForceNew in 2nd parameter of Navigate method.


Also, I have put a sample project file for you to quickly run and see how it works. You can download it from here - https://github.com/onlyutkarsh/LaunchUrlDemo/

About author
Utkarsh Shigihalli
Utkarsh Shigihalli
Utkarsh is passionate about software development and has experience in the areas of Azure, Azure DevOps, C# and TypeScript. Over the years he has worked as an architect, independent consultant and manager in many countries including India, United States, Netherlands and United Kingdom. He is a Microsoft MVP and has developed numerous extensions for Visual Studio, Visual Studio Code and Azure DevOps.
We Are
  • onlyutkarsh
    Utkarsh Shigihalli
    Microsoft MVP, Technologist & DevOps Coach

  • arora_tarun
    Tarun Arora
    Microsoft MVP, Author & DevOps Coach at Avanade

Do you like our posts? Subscribe to our newsletter!
Our Book