Monthly Archives

One Article

Visual Studio Tips

Using Visual Studio Browser Link to Speed Up Development

Posted by matteskolin on

I just discovered how to use Visual Studio browser link. This feature creates a constant connection between the browser and visual studio, allowing Visual Studio to trigger refreshes in the browser.

I had been under the impression that the only purpose for browser link was to test code in multiple browsers, to check compatibility, but I learned that it can also be used when working with a single browser to speed up the development process.

Specifically, the benefit comes when starting the application without debugging (Control + F5). When you start the application without debugging you are able to edit the code while the application is running. Normally, If you change assembly files, and then refresh using the browser, the application will automatically recompile the changed assemblies.

With browser link, you do NOT even have to refresh the page in the browser. You can trigger the refresh from within Visual Studio by clicking on “Refresh Linked Browsers” from the toolbar.

I am using Visual Studio 2019 Enterprise Preview with a .Net Core 2.2 MVC project. Seem Image below. I think it is essential here to create a shortcut to refresh linked browsers. I created mine to be (Control + `). The below screenshot shows another shortcut I tried that did not work because Ctrl + L is bound to so many different actions in my environment.

Enabling Browser link in a .Net Core app

To enable Browser link in .Net Core, you need to call the method next to the comment below. This will cause some javascript to be output to the page to create the link. Also make sure “Enable Browser” link is clicked in the above screenshot.

 public void Configure(IApplicationBuilder app, IHostingEnvironment env)
 {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();

                //Enable Browser Link
                app.UseBrowserLink();
            }
}