1

What do I have?

I have a ASP.NET Core 2.2 web app which references a Razor class library (RCL).

What do the docs say?

According to the docs (https://learn.microsoft.com/en-us/aspnet/core/razor-pages/ui-class?view=aspnetcore-2.2&tabs=visual-studio#override-views-partial-views-and-pages):

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.

What do I want?

I want to change this behavior to be the other way around.

  • First resolve the view from the RCL
  • If above isn't found, use the view from the web app

What have I tried?

Changing the ApplicationPart order (Did not work )

mvcBuilder.ConfigureApplicationPartManager(x =>
{
    var template = x.ApplicationParts[x.ApplicationParts.Count - 2];
    var templateViews = x.ApplicationParts[x.ApplicationParts.Count - 1];

    x.ApplicationParts.Remove(template);
    x.ApplicationParts.Remove(templateViews);

    x.ApplicationParts.Insert(0, template);
    x.ApplicationParts.Insert(1, templateViews);


    foreach (var part in x.ApplicationParts)
    {
        Log.Warning("ApplicationPart: {part}", part.Name);

    }
});
ApplicationPart: Template
ApplicationPart: Template.Views
ApplicationPart: MyWebApplication
ApplicationPart: Microsoft.AspNetCore.Identity.UI
ApplicationPart: Microsoft.AspNetCore.SpaServices
ApplicationPart: Microsoft.AspNetCore.SpaServices.Extensions
ApplicationPart: Microsoft.AspNetCore.Mvc.TagHelpers
ApplicationPart: Microsoft.AspNetCore.Mvc.Razor

Changing IViewLocationExpander (Did not work )

Duplicating existing ViewLocations and prefixing the views with the assembly name.

My question

  • Does anyone have any idea how to change this behavior?
  • You'll want a similar [solution to this](https://stackoverflow.com/questions/9838766/how-do-i-implement-a-custom-razorviewengine-to-find-views-in-non-standard-locati) but I don't work in Razor anymore so I've only got a version that works on old MVC – Liam Sep 20 '19 at 15:22
  • Might be this can help somehow [link] https://gunnarpeipman.com/aspnet-core-razor-class-library/ – Zbigniew Krumins May 07 '20 at 10:09

0 Answers0