Skip to content

Commit a693af3

Browse files
authored
Fix using obsolete WebHostBuilder in wasm DevServer/DebugProxy (#118679)
It was obsoleted in dotnet/aspnetcore#62785 Switch to `new HostBuilder().ConfigureWebHost` instead.
1 parent e749b39 commit a693af3

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

src/mono/browser/debugger/BrowserDebugHost/DebugProxyHost.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.AspNetCore.Hosting;
1010
using Microsoft.Extensions.Configuration;
1111
using Microsoft.Extensions.DependencyInjection;
12+
using Microsoft.Extensions.Hosting;
1213
using Microsoft.Extensions.Logging;
1314
using Microsoft.Extensions.Options;
1415

@@ -43,7 +44,8 @@ public static Task RunFirefoxServerLoopAsync(ProxyOptions options, string[] args
4344
public static async Task RunDevToolsProxyAsync(ProxyOptions options, string[] args, ILoggerFactory loggerFactory, CancellationToken token)
4445
{
4546
string proxyUrl = $"http://127.0.0.1:{options.DevToolsProxyPort}";
46-
IWebHost host = new WebHostBuilder()
47+
IHost host = new HostBuilder().ConfigureWebHost(webHostBuilder =>
48+
webHostBuilder
4749
.UseSetting("UseIISIntegration", false.ToString())
4850
.UseKestrel()
4951
.UseContentRoot(Directory.GetCurrentDirectory())
@@ -60,7 +62,7 @@ public static async Task RunDevToolsProxyAsync(ProxyOptions options, string[] ar
6062
config.AddCommandLine(args);
6163
})
6264
.UseUrls(proxyUrl)
63-
.Build();
65+
).Build();
6466

6567
if (token.CanBeCanceled)
6668
token.Register(async () => await host.StopAsync());

src/mono/wasm/host/BrowserHost.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using System.Threading.Tasks;
1414
using System.Web;
1515
using Microsoft.AspNetCore.Hosting;
16+
using Microsoft.Extensions.Hosting;
1617
using Microsoft.Extensions.Logging;
1718
using Microsoft.WebAssembly.AppHost.DevServer;
1819
using Microsoft.WebAssembly.Diagnostics;
@@ -80,7 +81,7 @@ private async Task RunAsync(ILoggerFactory loggerFactory, CancellationToken toke
8081
? aspnetUrls.Split(';', StringSplitOptions.RemoveEmptyEntries)
8182
: new string[] { $"http://127.0.0.1:{_args.CommonConfig.HostProperties.WebServerPort}", "https://127.0.0.1:0" };
8283

83-
(ServerURLs serverURLs, IWebHost host) = await StartWebServerAsync(_args,
84+
(ServerURLs serverURLs, IHost host) = await StartWebServerAsync(_args,
8485
urls,
8586
token);
8687

@@ -100,7 +101,7 @@ private async Task RunAsync(ILoggerFactory loggerFactory, CancellationToken toke
100101
await host.WaitForShutdownAsync(token);
101102
}
102103

103-
private async Task<(ServerURLs, IWebHost)> StartWebServerAsync(BrowserArguments args, string[] urls, CancellationToken token)
104+
private async Task<(ServerURLs, IHost)> StartWebServerAsync(BrowserArguments args, string[] urls, CancellationToken token)
104105
{
105106
Func<WebSocket, Task>? onConsoleConnected = null;
106107
if (args.ForwardConsoleOutput ?? false)

src/mono/wasm/host/DevServer/DevServer.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ namespace Microsoft.WebAssembly.AppHost.DevServer;
1717

1818
internal static class DevServer
1919
{
20-
internal static async Task<(ServerURLs, IWebHost)> StartAsync(DevServerOptions options, ILogger logger, CancellationToken token)
20+
internal static async Task<(ServerURLs, IHost)> StartAsync(DevServerOptions options, ILogger logger, CancellationToken token)
2121
{
2222
TaskCompletionSource<ServerURLs> realUrlsAvailableTcs = new();
2323

24-
IWebHostBuilder builder = new WebHostBuilder()
24+
IHostBuilder builder = new HostBuilder().ConfigureWebHost(webHostBuilder =>
25+
webHostBuilder
2526
.UseConfiguration(ConfigureHostConfiguration(options))
2627
.UseKestrel()
2728
.UseStaticWebAssets()
@@ -47,10 +48,10 @@ internal static class DevServer
4748
services.AddSingleton(realUrlsAvailableTcs);
4849
services.AddRouting();
4950
})
50-
.UseUrls(options.Urls);
51+
.UseUrls(options.Urls));
5152

5253

53-
IWebHost? host = builder.Build();
54+
IHost? host = builder.Build();
5455
await host.StartAsync(token);
5556

5657
if (token.CanBeCanceled)

src/mono/wasm/host/WebServer.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ namespace Microsoft.WebAssembly.AppHost;
2121

2222
public class WebServer
2323
{
24-
internal static async Task<(ServerURLs, IWebHost)> StartAsync(WebServerOptions options, ILogger logger, CancellationToken token)
24+
internal static async Task<(ServerURLs, IHost)> StartAsync(WebServerOptions options, ILogger logger, CancellationToken token)
2525
{
2626
TaskCompletionSource<ServerURLs> realUrlsAvailableTcs = new();
2727

28-
IWebHostBuilder builder = new WebHostBuilder()
28+
IHostBuilder builder = new HostBuilder().ConfigureWebHost(webHostBuilder =>
29+
webHostBuilder
2930
.UseKestrel()
3031
.UseStartup<WebServerStartup>()
3132
.ConfigureLogging(logging =>
@@ -49,12 +50,12 @@ public class WebServer
4950
services.AddSingleton(realUrlsAvailableTcs);
5051
services.AddRouting();
5152
})
52-
.UseUrls(options.Urls);
53+
.UseUrls(options.Urls));
5354

5455
if (options.ContentRootPath != null)
5556
builder.UseContentRoot(options.ContentRootPath);
5657

57-
IWebHost? host = builder.Build();
58+
IHost? host = builder.Build();
5859
await host.StartAsync(token);
5960

6061
if (token.CanBeCanceled)

0 commit comments

Comments
 (0)