I recently migrated my ASP.NET Core MVC Project to ASP.NET Core 2.0. The web application was migrated using Visual Studio 2017 version 15.3 Preview.
The application works fine in the development mode ( both from Visual studio and using the console dotnet run ) but when i publish it and host it in IIS (Version 10 ), it throws and error saying :
The view 'Index' was not found. The following locations were searched: /Areas/Admin/Views/Shared/Home/Index.cshtml ...
Note : I have a custom route configuration where the views are configured using a Custom ViewLocationExpander
This is what my project structure looks like :
Things that i have tried are :
In the .csproj :
<PreserveCompilationContext>true</PreserveCompilationContext>
In the Program.cs :
.UseContentRoot(Directory.GetCurrentDirectory())
I have configured the RazorViewEngineOptions as follows :
Including the following in .csproj did not work as well :
<ItemGroup>
<Content Update="wwwroot\**\*;**\*.cshtml;appsettings.json;web.config">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
If i try including the .cshtml files manually, it throws a duplicity error.
I have gone through a lots of articles and the official github links, but nothing is working.
Am i missing something out here ? Any suggestions would be greatly appreciated !!
I solved it finally.
First of all, I had to include the following in the PropertyGroup in the .csproj file
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
It must be because of my distributed Views structure.
I dont know why, but i also had to separately publish my Views folders (Views and Areas ) after publishing my application.
Note: Including the Views folders in .csproj for publishing did not help
After publishing my views, it gave an error in the browser saying Cannot find compilation library location for package 'Microsoft.Win32.Registry'.
Hence, I had to install the Microsoft.Win32.Registry package and publish my folder once again.
And that is how it worked.
Hope, it help someone facing a similar kind of issue.