How to fix “The view ‘Index’ was not found” on Azure Linux App Service

This weekend, I was working on my old MVC application. Azure was charging me around $55 a month for a Basic app service, while a similar Linux one only costs around $13. Migrating my MVC app from Windows to Linux would save me 42 dollars a month.

However, when publishing my app to the Linux app service, I ran into an issue. It threw the common InvalidOperationException: “The view ‘Index’ was not found“.

First I checked whether my folders and files were all correctly named (upper/lower case, etc). This was not the case. After some digging around, I found that my Visual Studio publish wasn’t publishing the Views folder. 

Luckily, the fix for this is an easy one. Just copy-paste the following code into your MVC project’s .csproj file. After this, try publishing your project to Azure again.

I hope this helps!

				
					  <Target Name="CopyCustomContentOnPublish" AfterTargets="Publish">
    <ItemGroup>
      <Views Include="Views\**" />
    </ItemGroup>
    <Copy SourceFiles="@(Views)" DestinationFolder="$(PublishDir)%(Views.RelativeDir)" />
  </Target>
				
			

Leave a Comment

Your email address will not be published.