Live reload with Asp.Net 5
Asked Answered
B

2

18

In Asp.Net 5 the development is faster because it compiles on save. But I still have to refresh the browser manually.

Is there a live reload option in Visual Studio, or should I use a gulp plugin for that?

Briannabrianne answered 9/10, 2015 at 9:4 Comment(0)
H
13

You can enable BrowserLink and while editing your code hit Ctrl+Alt+Enter to cause the browsers to refresh automatically. Alternatively you can hit the browser link refresh button in the Visual Studio ToolBar.

public void Configure(IApplicationBuilder application)
{
    // Only enable browser link if IHostingEnvironment says it's 
    // running in Development.
    if (this.hostingEnvironment.IsDevelopment())
    {
        // Allow updates to your files in Visual Studio to be shown in 
        // the browser. You can use the Refresh 
        // browser link button in the Visual Studio toolbar or Ctrl+Alt+Enter
        // to refresh the browser.

        application.UseBrowserLink();
    }
    // Omitted...
}

You also need to add the Browser Link NuGet package in your project.json:

"dependencies": {
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta7",
    // Omitted...
}
Horselaugh answered 9/10, 2015 at 9:9 Comment(6)
That works. Would be even better if that was triggered on save.Briannabrianne
That's a good idea. Go ahead and suggest it as an improvement in the ASP.NET GitHub Tooling project.Horselaugh
It is also slower than a normal refresh. Not sure why.Briannabrianne
It's using Signal-R to send a message to the browser using Web Sockets to update itself, so there is a slight overhead on the page. The cool thing is, you can open multiple browsers and watch them all refresh at the same time.Horselaugh
I added a +1 to the issue.Horselaugh
Please specify where shall I write the above Configure method. And my project doesn't have a project.json file. What should I do in that case?Power
H
9

context => Mats made a new extension which refreshes automatically after SAVE button. Grag the VS extension from visual studio gallery.

Save your VS changes and the browser is reloaded.

https://visualstudiogallery.msdn.microsoft.com/46eef4d9-045b-4596-bd7f-eee980bb5450

Honaker answered 20/2, 2016 at 23:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.