title: Self-hosted Net Core 3 application does not take port settings
body: <p>I feel silly asking this as there are dozens of articles on Net Core hosting, but I have tried everything and I am still having the issue.</p>
  
  <p>I am attempting to change the port used by a self-hosted web service. I have altered the launchSettings.json file.</p>
  
  <pre><code>"MyService": {
        "commandName": "Project",
        "environmentVariables": {
          "ASPNETCORE_URLS": "http://*:51248",
          "ASPNETCORE_ENVIRONMENT": "Development"
        },
        "applicationUrl": "http://localhost:51248"
      },
      "MyService": {
        "commandName": "Project",
        "environmentVariables": {
          "ASPNETCORE_URLS": "http://*:51248",
          "ASPNETCORE_ENVIRONMENT": "Release"
        },
        "applicationUrl": "http://localhost:51248"
      }
  
  </code></pre>
  
  <p>I have also attempted to set the port through direct configuration:</p>
  
  <pre><code>public static IHostBuilder CreateHostBuilder(string[] args) =&gt;
              Host.CreateDefaultBuilder(args)
                  .ConfigureServices((hostContext, services) =&gt;
                  {
                      services.AddHostedService&lt;MyServiceWorker&gt;();
                  })
                  .ConfigureWebHostDefaults(webBuilder =&gt;
                  {
                      webBuilder.UseUrls("http://*:51248");
                      webBuilder.UseStartup&lt;Startup&gt;();
                  })
                  .ConfigureWebHost(config =&gt; { config.UseUrls("http://*:51248"); })
                  .UseWindowsService()
                  .UseSerilog();
      }
  </code></pre>
  
  <p>Everything works fine if I run through Visual Studio, but if I run the executable directly, it still uses port 5000. If I run it as a Windows service, it seems to pick some random port.</p>
  
  <p>I have hit dozens of web sites, but have not found a solution. Does anyone have any suggestions?</p>