SAL SAL - 1 year ago 120
C# Question

ASP.NET Core: Finding a View - works in IIS Express debug but not in Kestrel 'published'

I've spent the afternoon googling and can't find anything that matches my problem.

I'm using ASP.NET Core 1.0.0 for a simple web site. All behaves fine when debugging in IIS-Express in VS 2015. But when I publish the site (either using the built-in VS2015 tools or manually using 'dotnet publish') I get a "The View 'xxx" was not found' error every time I try and access a page.

Here's the code:


public class CalcController : Controller
public IActionResult Index()
return View();

... etc ....


and here's a screenshot of my Views folder:

enter image description here

This all works absolutely fine in IIS Express within VS 2015. But when I publish and try running the published code I get this:

enter image description here

FWIW - I can serve static pages and js, css etc without any problems.

Any ideas?

Answer Source

in the project.json file of your web app, you need to include the views (and other needed files) in the publish options like this so that they are included in the published output:

"publishOptions": {
    "include": [

as far as I know views are not pre-compiled, at least by default though there may be some possible way to do that.

it is also possible to embed views into the dll like this:

 "buildOptions": {
    "embed": [ "Views/**", "js/**", "css/**" ]

which I do in class library projects that have controllers, but then you need to have startup logic to make it find those embedded views

    .AddRazorOptions(options =>
        options.FileProviders.Add(new EmbeddedFileProvider(
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download