Given a library referenced in a project. That library has precompiled views (see this post how to achieve it). So the lib has ABC.dll and ABC.PrecompiledViews.dll assemblies.
There's a view in library inside /Views/Shared/Index.cshtml
. And a controler which returns it.
Then I have an application references the library (both assemblies). MVC discovers and returns that Index view in runtime.
Now I create a view inside application in Views/Shared/Index.cshtml
. So its relative name is the same as in referenced view. By I doing this I mean that I want to override the view from the library.
When application is started from VS (Ctrl-F5) it works but the view in application is ignored.
When application is published (dotnet publish
) then the application fails on start with the following error:
InvalidOperationException: The following precompiled view paths differ only in case, which is not supported:
/Views/Shared/Index.cshtml
/Views/Shared/Index.cshtml
Microsoft.AspNetCore.Mvc.Razor.Internal.RazorViewCompiler..ctor(IFileProvider fileProvider, RazorTemplateEngine templateEngine, CSharpCompiler csharpCompiler, Action compilationCallback, IList precompiledViews, ILogger logger)
Besides the problem that the view is ignored when I run from VS it's meaningful behavior. The app has two similar view and can't understand which one to choose.
So the question is how to force MVC to use a particular view (from app instead of from lib)?
There's a method to separate views with same relative names when they are belong to different controllers. Here's nice discussion - Restrict route to controller namespace in ASP.NET Core But my case is a bit different.