title: use Kestrel in .NET Core worker project
body: <p>I created a new .NET Core worker project with the template provided by Visual Studio. I want to listen for incoming TCP messages and HTTP requests. I'm following <a href="https://github.com/davidfowl/MultiProtocolAspNetCore" rel="nofollow noreferrer">David Fowler's &quot;Multi-protocol Server with ASP.NET Core and Kestrel&quot; repository</a> on how to setup Kestrel.</p>
  <p>AFAIK all I have to do is to install the <strong>Microsoft.AspNetCore.Hosting</strong> package to get access to the <code>UseKestrel</code> method.</p>
  <p>In the <strong>Program.cs</strong> file I'm currently doing this</p>
  <pre><code>public class Program
  {
      public static void Main(string[] args)
      {
          CreateHostBuilder(args).Build().Run();
      }
  
      public static IHostBuilder CreateHostBuilder(string[] args) =&gt;
          Host.CreateDefaultBuilder(args)
              .ConfigureServices((hostContext, services) =&gt;
              {
                  services.AddHostedService&lt;Worker&gt;();
              });
  }
  </code></pre>
  <p>Unfortunately I can't append <code>UseKestrel</code> to the <code>ConfigureServices</code> method. I think this is because I'm working with the <code>IHostBuilder</code> interface instead of the <code>IWebHostBuilder</code> interface.</p>
  <p><em>This project should not be a Web API project, it should remain as a Worker project.</em></p>
  <p>Any ideas how to configure Kestrel for this?</p>
  <hr />
  <p>I tried to change the code to the code from the sample repository</p>
  <pre><code>using System.Net;
  using Microsoft.AspNetCore;
  using Microsoft.AspNetCore.Connections;
  using Microsoft.AspNetCore.Hosting;
  using Microsoft.Extensions.DependencyInjection;
  
  namespace Service
  {
      public class Program
      {
          public static void Main(string[] args)
          {
              CreateWebHostBuilder(args).Build().Run();
          }
  
          public static IWebHostBuilder CreateWebHostBuilder(string[] args) =&gt;
              WebHost.CreateDefaultBuilder(args)
                  .ConfigureServices(services =&gt;
                  {
                      // ...
                  })
                  .UseKestrel(options =&gt;
                  {
                      // ...
                  });
      }
  }
  </code></pre>
  <p>When doing so it is still not able to resolve <code>WebHost</code> and comes up with these errors</p>
  <ul>
  <li>
  <blockquote>
  <p>There is no argument given that corresponds to the required formal parameter 'middleware' of 'ConnectionBuilderExtensions.Run(IConnectionBuilder, Func&lt;ConnectionContext, Task&gt;)'</p>
  </blockquote>
  </li>
  <li>
  <blockquote>
  <p>The name 'WebHost' does not exist in the current context</p>
  </blockquote>
  </li>
  </ul>
  <p>I think this happens because the worker project does not use a Web SDK.</p>