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

前端 未结 16 1981
梦毁少年i
梦毁少年i 2020-12-09 15:53

I\'m trying to create a ASP.NET Core MVC test app running on OSX using VS Code. I\'m getting a \'view not found\' exception when accessing the default Home/index (or any oth

16条回答
  •  长情又很酷
    2020-12-09 16:07

    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()
            .Build()
            .Run();
    }
    

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

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

提交回复
热议问题