I have a case when the startup process of an ASP.NET Core 2.2 application occurs inside a library. The application calls that library to build and run the host.
The setup code in the library adds the application itself as an ApplicationPart to ASP.NET Core MVC, so that the application could define ASP.NET Core MVC controllers and views as well.
The problem I'm facing is that a view defined in the application is found when running from visual studio or using
dotnet run application.csproj
but is not found when running the application's .exe file alone.
Both the library and the application have an additional views assembly (autogenerated) with the names of LibraryName.Views.dll and ApplicationName.Views.dll and both of them contains all the views inside.
The application is targeting .NET Framework 4.8
What am I missing here?
Some logging of the process. The Controller's name is "CustomStatusDialogController".
Working (dotnet run):
Application started. Press Ctrl+C to shut down.
info: Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor[1]
Executing ViewResult, running view Index.
dbug: Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor[2]
The view path '/Views/CustomStatusDialog/Index.cshtml' was found in 8167.5568ms.
info: Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor[4]
Executed ViewResult - view Index executed in 10570.57ms.
Not working (application's .exe file)
...
Application started. Press Ctrl+C to shut down.
info: Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor[1]
Executing ViewResult, running view Index.
fail: Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor[3]
The view 'Index' was not found. Searched locations: /Views/LogMessages/Index.cshtml, /Views/CustomStatusDialog/Index.cshtml, /Views/Shared/Index.cshtml, /Pages/Shared/Index.cshtml
Thank you.
If you are using .NET Core 2.x Try defining MvcRazorCompileOnPublish flag in your project file
For .NET Core 3.x you can add CopyRazorGenerateFilesToPublishDirectory
Let me know if this helps