title: Running ASP.NET Core MVC as a Console Application Project without .NET Core SDK
body: <p><strong>Problem Background</strong></p>
  
  <p>I'm creating a tool, tha generates MVC solutions(*.sln) and building(with msbuild) them so they could be deployed. Tool requires .NET Framework 4.5.2.</p>
  
  <p>Now I want to generate ASP.NET Core MVC application. Such applications could be run under 4.5.X, but I'm unsure if msbuild could handle project.json(so i'm using packages.config) and I cannot install .NET Core as every tutorial indicate as prerequisite for developing ASP.NET Core. Currently I'm planning to deploy generated applications on Windows.</p>
  
  <p><strong>The Problem:</strong></p>
  
  <p>So instead of .NET Core project I've created a simple console application:
  <a href="https://i.stack.imgur.com/03Eku.png" rel="noreferrer"><img src="https://i.stack.imgur.com/03Eku.png" alt="enter image description here"></a>
  There I've installed there all packages needed, like:</p>
  
  <pre><code>  &lt;package id="Microsoft.AspNetCore.Mvc" version="1.0.1" targetFramework="net452" /&gt;
  </code></pre>
  
  <p>And SelfHosted the application using Kestrel:</p>
  
  <pre><code>    public class Program {
      static void Main() {
          var host = new WebHostBuilder()
              .UseKestrel()
              .UseIISIntegration()
              .UseStartup&lt;Startup&gt;()
              .Build();
  
          host.Run();
      }
  }
  </code></pre>
  
  <p>I've added Controller with a View. When I do a request, controller is hit, but View cannot be compiled in runtime:
  <a href="https://i.stack.imgur.com/6HI93.png" rel="noreferrer"><img src="https://i.stack.imgur.com/6HI93.png" alt="enter image description here"></a></p>
  
  <p>Is this behavior related to the fact I'm using <em>Console Application</em> and not <em>ASP.NET Core Web Application</em>? Is it possible to create a full-featured MVC application as a simple console application?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>I think I've found a workaround inspired from reading github <a href="https://github.com/aspnet/Razor/issues/755" rel="noreferrer">issues</a>:</p>
  
  <pre><code> public void ConfigureServices(IServiceCollection services) {
          services.AddMvc()
                  .AddRazorOptions(options =&gt; {
                                       var previous = options.CompilationCallback;
                                       options.CompilationCallback = context =&gt; {
                                                                         previous?.Invoke(context);
                                                                         var refs = AppDomain.CurrentDomain.GetAssemblies()
                                                                                             .Where(x =&gt; !x.IsDynamic)
                                                                                             .Select(x =&gt; MetadataReference.CreateFromFile(x.Location))
                                                                                             .ToList();
                                                                         context.Compilation = context.Compilation.AddReferences(refs);
                                                                     };
                                   });
      }
  </code></pre>
  
  <p>That seems to make Razor to render my view. But I'm not sure yet if it can be accepted as a solution.</p>