Sharing views (.cshtml files) between projects in asp.net core

I have a project that for various reasons has several controllers and views that are essentially the same. Currently, they are duplicated between projects, so each project has several copies. I was wondering if it's all the same, to put them in a separate project (for example, a class library project) and change the capabilities of the View Locator (IViewLocationExpander?) Or some other ways to make it look in another project for these views.

I know that this is possible in the “full” asp.net with a little hack, and it was never very clean or elegant, so I wondered if there is a better way with the asp.net core?

thank

+2
source share
1 answer

You can create an AspNetCore class library and use AspNetCore Precompiled Views . Also, as indicated in this fooobar.com/questions/384918 / ... . This should allow you to compile and share controllers and views of your choice. Views (.cshtml files) will no longer need to be deployed, as they will be compiled and available in this class library.

( ) Nuget . ( Nuget Nuget).

+1

Source: https://habr.com/ru/post/1669043/


All Articles