Certain Razor views not publishing

Viewed 5520

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?

5 Answers

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.

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

Depending on the version of Visual Studio, excluding and then including partial view or its folder may work or not. The most certain way to do it is to remove it from .csproj file and then include it again.

lets say _LoginPartial is not updated after publishing (especially if you have some razor code).

First open '.csproj' file, and remove

<Content Include="Views\Shared\_LoginPartial.cshtml" />

The build the project, and then add it again to .csproj, and rebuild and publish.

Another Solution From Visual Studio

  1. right-click on the file and "Exclude From Project".
  2. select the Project and click on "Show All Files" from Solution Explore (top horizontal menu bar on Solution Explore)
  3. right-click on the file that Excluded and Click on "Include In Project".

This will automatically modify the .csproj file.

Related