|
| 1 | +--- |
| 2 | +title: "WebHostBuilder, IWebHost, and WebHost are obsolete" |
| 3 | +description: "Learn about the breaking change in ASP.NET Core 10 where WebHostBuilder, IWebHost, and WebHost are marked as obsolete." |
| 4 | +ms.date: 09/05/2025 |
| 5 | +ai-usage: ai-generated |
| 6 | +ms.custom: https://github.com/aspnet/Announcements/issues/526 |
| 7 | +--- |
| 8 | + |
| 9 | +# WebHostBuilder, IWebHost, and WebHost are obsolete |
| 10 | + |
| 11 | +<xref:Microsoft.AspNetCore.Hosting.WebHostBuilder>, <xref:Microsoft.AspNetCore.Hosting.IWebHost>, and <xref:Microsoft.AspNetCore.WebHost> have been marked as obsolete in .NET 10. `WebHostBuilder` was replaced by `HostBuilder` ([generic host](/aspnet/core/fundamentals/host/generic-host)) in ASP.NET Core 3.0, and `WebApplicationBuilder` was introduced in ASP.NET Core 6.0. These newer alternatives are where future investments will occur. |
| 12 | + |
| 13 | +## Version introduced |
| 14 | + |
| 15 | +.NET 10 RC 1 |
| 16 | + |
| 17 | +## Previous behavior |
| 18 | + |
| 19 | +Previously, you could use `WebHostBuilder` to configure and build a web host without any compile-time warnings. |
| 20 | + |
| 21 | +## New behavior |
| 22 | + |
| 23 | +Starting in .NET 10, using `WebHostBuilder` produces a compiler warning with diagnostic ID `ASPDEPR004`: |
| 24 | + |
| 25 | +> warning ASPDEPR004: WebHostBuilder is deprecated in favor of HostBuilder and WebApplicationBuilder. For more information, visit <https://aka.ms/aspnet/deprecate/004>. |
| 26 | +
|
| 27 | +Using `IWebHost` or `WebHost` produces a compiler warning with diagnostic ID `ASPDEPR008`: |
| 28 | + |
| 29 | +> warning ASPDEPR008: WebHost is obsolete. Use HostBuilder or WebApplicationBuilder instead. For more information, visit <https://aka.ms/aspnet/deprecate/008>. |
| 30 | +
|
| 31 | +## Type of breaking change |
| 32 | + |
| 33 | +This change can affect [source compatibility](../../categories.md#source-compatibility). |
| 34 | + |
| 35 | +## Reason for change |
| 36 | + |
| 37 | +`HostBuilder` and <xref:Microsoft.AspNetCore.Builder.WebApplication> have all the features of `WebHostBuilder` and are the focus of future investment. `WebHostBuilder` was replaced by the generic host in ASP.NET Core 3.0, and minimal APIs with <xref:Microsoft.AspNetCore.Builder.WebApplicationBuilder> were introduced in ASP.NET Core 6.0. These newer hosting models provide better integration with the .NET ecosystem and are the recommended approach for new applications. |
| 38 | + |
| 39 | +## Recommended action |
| 40 | + |
| 41 | +Migrate from `WebHostBuilder` to either [`HostBuilder`](/aspnet/core/fundamentals/host/generic-host) or [`WebApplication`](/aspnet/core/fundamentals/minimal-apis/webapplication): |
| 42 | + |
| 43 | +- For applications that need the full hosting capabilities, migrate to `HostBuilder`: |
| 44 | + |
| 45 | + **Before:** |
| 46 | + |
| 47 | + ```csharp |
| 48 | + var hostBuilder = new WebHostBuilder() |
| 49 | + .UseContentRoot(Directory.GetCurrentDirectory()) |
| 50 | + .UseStartup() |
| 51 | + .UseKestrel(); |
| 52 | + // Test code might use TestServer: |
| 53 | + var testServer = new TestServer(hostBuilder); |
| 54 | + ``` |
| 55 | + |
| 56 | + **After:** |
| 57 | + |
| 58 | + ```csharp |
| 59 | + using var host = new HostBuilder() |
| 60 | + .ConfigureWebHost(webHostBuilder => |
| 61 | + { |
| 62 | + webHostBuilder |
| 63 | + .UseTestServer() // If using TestServer. |
| 64 | + .UseContentRoot(Directory.GetCurrentDirectory()) |
| 65 | + .UseStartup() |
| 66 | + .UseKestrel(); |
| 67 | + }) |
| 68 | + .Build(); |
| 69 | + await host.StartAsync(); |
| 70 | + |
| 71 | + var testServer = host.GetTestServer(); |
| 72 | + ``` |
| 73 | + |
| 74 | +- For new applications, especially those using minimal APIs, migrate to <xref:Microsoft.AspNetCore.Builder.WebApplicationBuilder>. |
| 75 | + |
| 76 | +## Affected APIs |
| 77 | + |
| 78 | +- <xref:Microsoft.AspNetCore.Hosting.WebHostBuilder?displayProperty=fullName> |
| 79 | +- <xref:Microsoft.AspNetCore.Hosting.IWebHost?displayProperty=fullName> |
| 80 | +- <xref:Microsoft.AspNetCore.WebHost?displayProperty=fullName> |
| 81 | + |
| 82 | +## See also |
| 83 | + |
| 84 | +- [Generic Host in ASP.NET Core](/aspnet/core/fundamentals/host/generic-host) |
| 85 | +- [Minimal APIs with WebApplication](/aspnet/core/fundamentals/minimal-apis/webapplication) |
| 86 | +- [HostBuilder replaces WebHostBuilder](/aspnet/core/migration/22-to-30#hostbuilder-replaces-webhostbuilder) |
| 87 | +- [Introducing WebApplication](/aspnet/core/migration/50-to-60#new-hosting-model) |
0 commit comments