https://github.com/quickz/cshtml-class-library-example
An example of how to use ASP.NET Core MVC project views from a razor class library.
https://github.com/quickz/cshtml-class-library-example
asp-net-core asp-net-core-mvc cshtml example razor reuse
Last synced: 6 months ago
JSON representation
An example of how to use ASP.NET Core MVC project views from a razor class library.
- Host: GitHub
- URL: https://github.com/quickz/cshtml-class-library-example
- Owner: Quickz
- License: mit
- Created: 2025-07-17T20:35:32.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2025-07-17T21:54:39.000Z (7 months ago)
- Last Synced: 2025-07-18T00:07:30.259Z (7 months ago)
- Topics: asp-net-core, asp-net-core-mvc, cshtml, example, razor, reuse
- Language: HTML
- Homepage:
- Size: 1000 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cshtml file re-use example
An example of how to use ASP.NET Core MVC project views from a razor class library.
## Enabling run-time compilation
### How to enable run-time compilation for the MVC project
#### 1. Install this NuGet package on to the MVC project
```
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
```
#### 2. Add this on the startup file
```csharp
builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();
```

### How to enable run-time compilation for the razor class library
#### 1. Install this NuGet package on to the razor class library
```
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
```
#### 2. Update MVC project startup file to include this
```csharp
builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation(options =>
{
// Used to enable run-time compilation for the razor class library views.
// If removed run-time compilation will only be available for the main project.
if (builder.Environment.IsDevelopment())
{
var path = Path.Combine(
builder.Environment.ContentRootPath,
"../SharedViews");
var fileProvider = new PhysicalFileProvider(path);
options.FileProviders.Add(fileProvider);
}
});
```