A Professional ASP.NET Core - Razor Class Library

Razor views, pages, controllers, page models, Razor components, View components, and data models can be built into a Razor class library (RCL). The RCL can be packaged and reused. Applications can include the RCL and override the views and pages it contains. When a view, partial view, or Razor Page is found in both the web app and the RCL, the Razor markup (.cshtml file) in the web app takes precedence.

Create project

Choose Razor Class Library.

Name it as RazorSample.

Select .NET 5.0.

You can see the RCL project structure.

To test RCL create a MVC Wep App.

Name it as WebApplicationSample.

Select .NET 5.0.

The final solution structure should like below.


Most of the information in this article has gathered from various references.