I have created a new .Net Core MVC web app in Visual Studio 2015. The IDE is fully updated, and I have the latest .net core SDK installed. It consists of the solution file and multiple project files. I can successfully run it and get to the home page.
I have then opened up the root folder (solution folder) in Visual Studio Code and attempted to run it. It seems to start ok, however it can't find the default view for "Views/Home/Index.cshtml".
I get the following error:
InvalidOperationException: The view 'Index' was not found. The following locations were searched: /Views/Home/Index.cshtml /Views/Shared/Index.cshtml
The program.cs file is as follows:
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
The project.json has the following:
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
}
I imagine this is due to where it is trying to look for the views, as I am at a solution level, not a project level from within VSC.
Anyone any ideas?
I ran into this same scenario as well:
At this point you can compile and run the project, but it fails in finding the views, as you say.
The solution I've found is to edit the current working directory (cwd
property) configuration in .vscode\launch.json
:
And make it to point into the Web project folder:
Where the WebProject
folder is equivalent to Project root
in the previous answer's example.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With