To add live reloading when developing Asp.Net Core Views, it is recommended to upgrade to .Net Core 3.1. This makes it easier to add in the Nuget package for recompilation.
In case you have a .Net Core 2 app, follow the MSDN guide here:
https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio
After the app runs as .Net Core 3.1, run the following (procedure below is tested okay with VS 2019 and Chrome as the browser 'linked' to the reloading:
Edit the .csproj file by selecting the project and right clicking and selecting Edit project file in VS 2019. Past in these two Nuget package references and run dotnet restore, then dotnet build and finally dotnet run.
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="3.1.5" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.2.0" />
</ItemGroup>
The runtime compilation and Browserlink should both be added. The first will rebuild your edited razor views (cshtml) and BrowserLink reloads your browser while debugging, after the razor view is updated.
Also download this Visual Studio Extension, "Browser reload on save":
https://marketplace.visualstudio.com/items?itemName=MadsKristensen.BrowserReloadonSave
You will have to close all Visual Studio processes to start installing Mad Kristensen's browser extension.
In your Startup class you should inside ConfigureServices add these two lines, specifying AddRazorRunitmeCompilation:
services.AddRazorPages().AddRazorRuntimeCompilation();
services.AddControllersWithViews().AddRazorRuntimeCompilation();
And finally at the top of the Configure method in the Startup class add in BrowserLink. Note, add this at the top of the Configure method such that the pipeline is adding BrowserLink correct.
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
}
Now, just start up your app with F5 and start editing a razor file. If all was set up correct, you should now see your razor view reload in the Browser. This makes it easier to edit and adjust razor views!
Share this article on LinkedIn.
This comment has been removed by a blog administrator.
ReplyDeleteimprove your business startup by choosing mvc core services. you can get thses managable web hosting services.
ReplyDeleteDubai VPS Server
Wonderful information of dedicated server and other web hosting services!!!!!, I like this post, and really its too much help full for me. Get an amazing dedicated web hosting services.
ReplyDeleteUK VPS Server Hosting
Happy to visit your blog, I am by all accounts forward to more solid articles and I figure we as a whole wish to thank such huge numbers of good articles, blog to impart to us.data science certification
ReplyDeleteGreat blog!! I hope you're going to post an artificial intelligence blog.
ReplyDeleteartificial intelligence course in noida
I want you to thank for your time of this wonderful read!!! I definately enjoy every little bit of it and I have you bookmarked to check out new stuff of your blog a must read blog!
ReplyDeletedata science training in hyderabad
I at last discovered extraordinary post here.I will get back here. I just added your blog to my bookmark locales. thanks.Quality presents is the vital on welcome the guests to visit the page, that is the thing that this website page is giving.
ReplyDeletedigital marketing course aurangabad
Nice to know the live reloads in asp.net development.
ReplyDeleteVisual Foxpro to .Net and Visual Foxpro Migration