From 53e6db3edef4c59fd5c79a9e7b0f9755c7efcdeb Mon Sep 17 00:00:00 2001 From: "Spencer G. Jones" Date: Sun, 4 Sep 2022 09:50:03 -0600 Subject: [PATCH] Convert http driver to latest ASP.NET Core version when running in .NET 6 --- build/Packages.props | 12 ++++++------ src/OmniSharp.Http/Host.cs | 13 +++++++++++++ .../Middleware/StopServerMiddleware.cs | 10 ++++++++++ src/OmniSharp.Http/OmniSharp.Http.csproj | 7 +++++++ 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/build/Packages.props b/build/Packages.props index e72fc930ab..3adeb273ba 100644 --- a/build/Packages.props +++ b/build/Packages.props @@ -2,7 +2,6 @@ - 2.2.0 6.0.0 17.3.0 17.3.1 @@ -20,11 +19,6 @@ - - - - - @@ -94,5 +88,11 @@ + + + + + + diff --git a/src/OmniSharp.Http/Host.cs b/src/OmniSharp.Http/Host.cs index ae35b31459..8832935e28 100644 --- a/src/OmniSharp.Http/Host.cs +++ b/src/OmniSharp.Http/Host.cs @@ -1,6 +1,9 @@ using System; using System.Diagnostics; using Microsoft.AspNetCore.Hosting; +#if NETCOREAPP +using Microsoft.Extensions.Hosting; +#endif using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using OmniSharp.Eventing; @@ -38,7 +41,13 @@ public void Start() .AddCommandLine(new[] { "--server.urls", $"http://{_serverInterface}:{_serverPort}" }); var builder = new WebHostBuilder() +#if NETCOREAPP + .UseKestrel(config => { + config.AllowSynchronousIO = true; + }) +#else .UseKestrel() +#endif .ConfigureServices(serviceCollection => { serviceCollection.AddSingleton(_environment); @@ -56,7 +65,11 @@ public void Start() { app.Start(); +#if NETCOREAPP + var appLifeTime = app.Services.GetRequiredService(); +#else var appLifeTime = app.Services.GetRequiredService(); +#endif Console.CancelKeyPress += (sender, e) => { diff --git a/src/OmniSharp.Http/Middleware/StopServerMiddleware.cs b/src/OmniSharp.Http/Middleware/StopServerMiddleware.cs index 18e65cae6d..4fb62fd054 100644 --- a/src/OmniSharp.Http/Middleware/StopServerMiddleware.cs +++ b/src/OmniSharp.Http/Middleware/StopServerMiddleware.cs @@ -1,15 +1,25 @@ using System.Threading; using System.Threading.Tasks; +#if NETCOREAPP +using Microsoft.Extensions.Hosting; +#else using Microsoft.AspNetCore.Hosting; +#endif using Microsoft.AspNetCore.Http; namespace OmniSharp.Http.Middleware { class StopServerMiddleware { +#if NETCOREAPP + private readonly IHostApplicationLifetime _lifetime; + + public StopServerMiddleware(RequestDelegate next, IHostApplicationLifetime lifetime) +#else private readonly IApplicationLifetime _lifetime; public StopServerMiddleware(RequestDelegate next, IApplicationLifetime lifetime) +#endif { _lifetime = lifetime; } diff --git a/src/OmniSharp.Http/OmniSharp.Http.csproj b/src/OmniSharp.Http/OmniSharp.Http.csproj index 0817374654..b1a7305632 100644 --- a/src/OmniSharp.Http/OmniSharp.Http.csproj +++ b/src/OmniSharp.Http/OmniSharp.Http.csproj @@ -5,6 +5,10 @@ AnyCPU + + + + @@ -14,8 +18,11 @@ + + +