Using Razor class libraries
Everything related to a Razor Page can be compiled into a class library for easier reuse in multiple projects. With ASP.NET Core 3.0 and later, this can include static files such as HTML, CSS, JavaScript libraries, and media assets such as image files. A website can either use the Razor Page's view as defined in the class library or override it.
Creating a Razor class library
Let's create a new Razor class library:
Use your preferred code editor to add a new project, as defined in the following list:
- Project template: Razor Class Library /
razorclasslib
- Checkbox/switch: Support pages and views /
-s
- Workspace/solution file and folder:
PracticalApps
- Project file and folder:
Northwind.Razor.Employees
-s
is short for the --support-pages-and-views
switch that enables the class library to use Razor Pages and .cshtml
file views.
Disabling compact folders for Visual Studio Code
Before...