Originally posted to: http://www.davepaquette.com/archive/2016/07/16/loading-view-components-from-a-class-library-in-asp-net-core.aspx
In this article we take a look at how view components can be implemented in a separate class library and shared across multiple web applications.
share Library
step 1. Creating a class library
step 2.add a view component class to the project
step 3.added a Default.cshtml view to the ViewComponentLibrary in the Views\Shared\Components\Simple folder
step 4.For this view to be recognized by the web application, we need to include the cshtml files as embedded resources in the class library. Currently, this is done by adding the following setting to the project.json file.
How to use
step 1.Referencing external view components
step 2.invoke the view component in ASP.NET Core MVC application.
https://github.com/iaspnetcore/wwwiaspnetcorecom/blob/363cc9fa33ad782e606d459ee701f3b4398df1d1/src/ProjectMenuLibrary/MenuWebApp/MenuWebApp.csproj
You can take a look at the full source code on GitHub. https://github.com/AspNetMonsters/ExternalViewComponents
useful links
https://www.davepaquette.com/archive/2016/07/16/loading-view-components-from-a-class-library-in-asp-net-core.aspx
Create reusable UI using the Razor class library project in ASP.NET Core
https://learn.microsoft.com/en-us/aspnet/core/razor-pages/ui-class?view=aspnetcore-9.0&tabs=visual-studio