Missing assembly reference in Razor view


I have a MVC application which works fine when returning JSON for my API controllers. I've added a controller which should return a razor view, however I'm getting the following error when trying to load the page:

One or more compilation references are missing. Possible causes include a missing 'preserveCompilationContext' property under 'buildOptions' in the application's project.json.

The type or namespace name 'DevTestViewModel' does not exist in the namespace 'MyApp.Api.Models' (are you missing an assembly reference?)

I've simplified my view to:

@model List<MyApp.Api.Models.DevTestViewModel>

<h1>Hello World</h1>

My model class is:

namespace MyApp.Api.Models {
    public class DevTestViewModel {

        public int Id { get; set; }

        public string Name { get; set; }


I've tried adding a _ViewImports.cshtml:

@using MyApp.Api

I've also followed the suggestion in the error and set preserveCompilationContext in my project.json but it's made no difference:

"buildOptions": {
  "emitEntryPoint": true,
  "preserveCompilationContext": true

It works fine when debugging locally. It's only once I publish to Azure that I'm have the problem. Not sure what I'm missing.

It looks like there was an issue with the deployment to Azure. Re-creating the Web App in Azure and then redeploying fixed the issue.