Skip to content

Commit ff543ed

Browse files
authored
Document WebHostBuilder, IWebHost, and WebHost deprecation breaking change (#48274)
1 parent cea304a commit ff543ed

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

docs/core/compatibility/10.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ If you're migrating an app to .NET 10, the breaking changes listed here might af
2727
| [IPNetwork and ForwardedHeadersOptions.KnownNetworks are obsolete](aspnet-core/10/ipnetwork-knownnetworks-obsolete.md) | Source incompatible | Preview 7 |
2828
| [Microsoft.Extensions.ApiDescription.Client package deprecated](aspnet-core/10/apidescription-client-deprecated.md) | Source incompatible | Preview 7 |
2929
| [Razor run-time compilation is obsolete](aspnet-core/10/razor-runtime-compilation-obsolete.md) | Source incompatible | Preview 7 |
30+
| [WebHostBuilder, IWebHost, and WebHost are obsolete](aspnet-core/10/webhostbuilder-deprecated.md) | Source incompatible | RC 1 |
3031

3132
## Containers
3233

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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)

docs/core/compatibility/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ items:
2626
href: aspnet-core/10/apidescription-client-deprecated.md
2727
- name: Razor run-time compilation is obsolete
2828
href: aspnet-core/10/razor-runtime-compilation-obsolete.md
29+
- name: WebHostBuilder, IWebHost, and WebHost are obsolete
30+
href: aspnet-core/10/webhostbuilder-deprecated.md
2931
- name: Containers
3032
items:
3133
- name: Default .NET images use Ubuntu

0 commit comments

Comments
 (0)