title: MVC Console app in VS 2017 - unable to serve razor views
body: <p>I have created basic MVC application in asp.net core with Visual Studio 2017.
  I got an error when trying to render index.cshtml</p>
  
  <blockquote>
    <p>An error occurred during the compilation of a resource required to process this request. Please review the following specific error details and modify your source code appropriately.</p>
    
    <p>Generated Code</p>
    
    <p>One or more compilation references are missing. Possible causes
    include a missing 'preserveCompilationContext' property under
    'buildOptions' in the application's project.json.</p>
    
    <p>The type or namespace name 'System' could not be found (are you
    missing a using directive or an assembly reference?)</p>
    
    <p>+
    using System;</p>
    
    <p>...</p>
  </blockquote>
  
  <p>My whole console application is as short as it can be:</p>
  
  <pre><code>using Microsoft.AspNetCore.Builder;
  using Microsoft.AspNetCore.Hosting;
  using Microsoft.AspNetCore.Mvc;
  using Microsoft.Extensions.DependencyInjection;
  using System;
  using System.IO;
  
  namespace ConsoleApp1
  {
      class Program
      {
          static void Main(string[] args)
          {
              Console.WriteLine("Hello World!");
              var host = new WebHostBuilder()
                  .UseContentRoot(Directory.GetCurrentDirectory())
                  .UseKestrel()
                  .UseStartup&lt;Startup&gt;()
                  .Build();
  
              host.Run();
          }
      }
  
      class Startup
      {
          public void ConfigureServices(IServiceCollection services)
          {
              services.AddMvc();
          }
  
          public void Configure(IApplicationBuilder app)
          {
              app.UseDeveloperExceptionPage();
              app.UseMvc();
          }
      }
  
      public class HomeController : Controller
      {
          [HttpGet("/")]
          public ActionResult Index()
          {
              ViewBag.Message = "Hello world!";
              ViewBag.Time = DateTime.Now;
  
              return View();
          }
      }
  }
  </code></pre>
  
  <p>Structure of my "project"</p>
  
  <p><a href="https://i.stack.imgur.com/FOK62.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FOK62.png" alt="Structure of my project"></a></p>
  
  <p>View</p>
  
  <p><a href="https://i.stack.imgur.com/MDx67.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MDx67.png" alt="Index.cshtml"></a></p>
  
  <p>It's funny because the error tells me that I have to change something in project.json, but since Visual Studio 2017 there is no project.json anymore.</p>
  
  <p>My view is in fact simple static html file and does not require any references to models or anything. But errors are complaining about missing types:</p>
  
  <p><a href="https://i.stack.imgur.com/XTuMn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XTuMn.png" alt="enter image description here"></a></p>
  
  <p>I tried to compare my project to web application template but I havent found what's causing razor views not to build in console application. </p>
  
  <p>What am I missing here?</p>