title: How to add REST API to console app written in .NET Framework 4.8 using .NET generic host?
body: <p>I've written a small Windows service that hosts a number of IHostedService based classes using the .NET generic host. I'd like to add the ability to talk to the service through a REST API, and thought the .NET generic host setup should let me do that fairly easily: just add Microsoft.AspNetCore, Microsoft.AspNetCore.Hosting and start with adding a .ConfigureWebHost to the IHostBuilder. But it seems like the combination of .NET Framework and .NET generic host prohibits that from working.... The program.cs looks roughly like:</p>
  
  <pre><code>using Microsoft.AspNetCore.Hosting;
  using Microsoft.Extensions.Configuration;
  using Microsoft.Extensions.DependencyInjection;
  using Microsoft.Extensions.Hosting;
  
  namespace Myservice
  {
    class Program
    {
      static async Task Main(string[] args)
      {
        IHostBuilder builder = Host.CreateDefaultBuilder(args)
          .ConfigureHostConfiguration(...)
          .ConfigureAppConfiguration(...)
          // ConfigureWebHost can't be found by the compiler
          // Neither can .ConfigureWebHostDefaults
          .ConfigureWebHost(...)
          .ConfigureLogging(...)
          .ConfigureServices(...);
  
        if (CommandLine.RunAsService)
        {
          builder.UseWindowsService();
        }
  
        await builder.Build().RunAsync();
      }
    }
  }
  </code></pre>
  
  <p>I've seen some hints that the particular project type matters. I started out with a standard .NET Framework Console App - so project file looking something like:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"&gt;
    &lt;Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /&gt;
  ...
  </code></pre>
  
  <p>but have also tried with a project built from the ASP.NET Core Web Application template using .NET Framework. (.NET Framework is a requirement to make use of particular assemblies the service needs.) That looked something like:</p>
  
  <pre><code>&lt;Project Sdk="Microsoft.NET.Sdk.Web"&gt;
  
    &lt;PropertyGroup&gt;
      &lt;TargetFramework&gt;net48&lt;/TargetFramework&gt;
    &lt;/PropertyGroup&gt;
    ...
  </code></pre>
  
  <p>It seems like this ought to work somehow, but I can't find the right combination....</p>