Mvc: Views not being included when publishing

Created on 8 Jun 2016  路  5Comments  路  Source: aspnet/Mvc

I'm not sure if this should be posted in this repo or with the tooling, but here goes.

When deploying using RC2 it seems the views aren't being included. If I run the executable from the command line post-publish and then launch localhost:5000 in a browser I get a blank screen and a 500 server error in the browser and a bunch of error messages relating to missing views on the command line, for example:

fail: Microsoft.AspNetCore.Server.Kestrel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60[13]
Connection id "0HKSF70AEDSCP": An unhandled exception was thrown by the application.
System.InvalidOperationException: The view 'Index' was not found. The following locations were searched:
/Areas/Website/Views/Home/Index.cshtml
/Areas/Website/Views/Shared/Index.cshtml
/Views/Shared/Index.cshtml
   at Microsoft.AspNetCore.Mvc.ViewEngines.ViewEngineResult.EnsureSuccessful(IEnumerable``1 originalLocations)
   at Microsoft.AspNetCore.Mvc.ViewResult.<ExecuteResultAsync>d__26.MoveNext()

If I manually copy over the views from the development folder and restart the executable then everything kicks in perfectly.

The exact same occurs whether I deploy to a local folder or to a remote server running IIS with WebDeploy. The project was created in VS2015 with Tooling Preview 1 installed.

question

All 5 comments

Can you paste in your project.json? Something there likely needs to be updated (thinking your publishOptions:include doesn't include the Areas folder).

Exactly right, @rynowak. I manually added "Areas" to the include section and everything is working perfectly now, thanks.

"publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "appsettings.json",
      "web.config"
    ]
  }

When I initially added the areas to my project I did so manually . Would VS have taken care of this for me if I scaffolded new areas, or ought the default project.json have "Areas" added to it?

I'm thinking we might want to add this to the template. https://github.com/aspnet/Templates/issues/595

We answered your question and have made this update to the templates for 1.0.0 so I'm going to close this bug. Thanks for the suggestion.

Please reopen if you feel we haven't addressed this.

I think, You must to update the launch.json file, look inside of .vscode directory and change the
"cwd": "${workspaceRoot}" maybe you are working in a solution and you must to specify the current working directory to mention the path of your "project directory"

Was this page helpful?
0 / 5 - 0 ratings