Ray
Ray

Reputation: 12441

Refresh Razor Class Library changes with BrowserLink

BrowserLink works well with an Asp.net Core webapp, but when it comes to a Razor Class Library (RCL) I just don't see it working. Every time I make a change in a .cshtml view inside my RCL, I have to do a rebuild on the solution to see the change which is not productive at all. Has someone been able to get this working with RCL? Thanks.

Upvotes: 1

Views: 319

Answers (1)

96marrs
96marrs

Reputation: 161

You need to add a PhysicalFileProvider in your Startup.cs ConfigureServices of the WebApp that you are using Razor Class Library components on. I have two Razor Class Library projects in the same solution as my website set up and named as so:

  • WebApp (.net core webapp)
  • ModelLibrary (Razor Class Library)
  • ViewComponentLibrary (Razor Class Library)

In Startup ConfigureServices of the WebApp...

services.Configure<RazorViewEngineOptions>(options => 
        {
            options.FileProviders.Add(new PhysicalFileProvider(Path.Combine(hosting.ContentRootPath, "..\\ViewComponentLibrary")));
        });

The "hosting" is an IHostingEnvironment Dependency Injection in the Startup class.

You would obviously need to change "ViewComponentLibrary" to whatever you named your own Razor Class Library. Now, when you make changes they are shown without rebuilding the solution.

Upvotes: 1

Related Questions