Using Razor class libraries
Everything related to a Razor page can be compiled into a class library for easier reuse. With .NET Core 3.0 and later, this can include static 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 us create a new Razor class library:
- Create a subfolder in
PracticalApps
namedNorthwindEmployees
. - In Visual Studio Code, add the
NorthwindEmployees
folder to thePracticalApps
workspace. - Navigate to Terminal | New Terminal and select
NorthwindEmployees
. - In TERMINAL, enter the following command to create a Razor Class Library project:
dotnet new razorclasslib -s
More Information: The -s
option is short for --support-pages-and-views
that enables the class library to use Razor Pages and .cshtml
file views.
Disabling compact folders
Before we implement our Razor class library, I want...