Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Certain Razor views not publishing

Using VS 2017 with MVC 5 Razor views. When I publish my application, a handful of specific views do not get copied over.

I'd discovered several SE questions on this same issue from back in the 2010-2011 timeframe. At the time, the issue was that Build Action in the file's properties was not set to Content due to a bug in some early RC which has since been resolved. Well, all of mine already do day Content for Build Action.

Any reason why only a small number of views are not making it in the publish?

like image 244
oscilatingcretin Avatar asked Jul 25 '17 15:07

oscilatingcretin


3 Answers

As far as I'm aware, there are only 2 things that can cause this to happen.

  1. As you say in the question, the build action for each view needs to be set to "Content"
  2. The view files need to be included in the project file, so in the .csproj file there should be a line like this:

    <Content Include="Views\ControllerName\Index.cshtml" />
    
like image 123
DavidG Avatar answered Oct 20 '22 23:10

DavidG


Another one would be to set this in your csproje file. This was missing in mine, which caused it to make a precompiledviews.dll in my publish:

<MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>

Set it to false explicitely in order to publish .cshtml files.

like image 40
Robin Avatar answered Oct 20 '22 21:10

Robin


Visual Studio -> Right click on "Views" in solution explorer. Click "Publish Views". This will set all the views to Content"

like image 27
moto_geek Avatar answered Oct 20 '22 21:10

moto_geek