How do I solve a "view not found" exception in asp.net core mvc project

I found this missing piece. I ended up creating a ASP.NET Core project in VS2015 and then compare for differences. It turns out I was missing .UseContentRoot(Directory.GetCurrentDirectory()) from WebHostBuilder in main.

After adding this:

public static void Main(string[] args)
{
    new WebHostBuilder()
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseStartup<Startup>()
        .Build()
        .Run();
}

I then got an exception regarding missing preserveCompilationContext. Once added in project.json my view shows correct.

"buildOptions": {
    "preserveCompilationContext": true,
    "emitEntryPoint": true
},

In my case, the build action was somehow changed to Embedded resource which is not included in published files.

Changing Embedded resource to Content resolves my issue.

enter image description here

Tags:

Asp.Net Core