Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
5102b25
Initial plan
Copilot Jul 17, 2025
54f0cdd
Mark WebHostBuilder class as obsolete with placeholder message
Copilot Jul 17, 2025
8c3f586
Update WebHostBuilder usage to HostBuilder pattern in four target files
Copilot Jul 17, 2025
8869208
fixup
BrennanConroy Jul 17, 2025
5407fb0
Address review feedback: Add pragma disables and update to HostBuilde…
Copilot Jul 17, 2025
dd80d9c
Add pragma warning suppression for WebHost.cs and remove from WebHost…
Copilot Jul 17, 2025
3f16853
Update TestServerTests.cs and HttpsConfigurationTests.cs to use HostB…
Copilot Jul 17, 2025
d028735
test
BrennanConroy Jul 17, 2025
95e6eaa
fix tests
BrennanConroy Jul 18, 2025
194d366
Remove nowarn settings and start converting TestHost tests to HostBui…
Copilot Jul 18, 2025
e87e383
Complete conversion of RequestBuilderTests, ClientHandlerTests, and W…
Copilot Jul 18, 2025
bd4d52f
Start converting TestHost test files to HostBuilder pattern
Copilot Jul 19, 2025
b146f4d
Complete conversion of HttpContextBuilderTests.cs to HostBuilder pattern
Copilot Jul 19, 2025
2f609b9
Partial conversion of TestClientTests.cs and TestServerTests.cs to Ho…
Copilot Jul 19, 2025
dfcad52
Complete TestHost test file WebHostBuilder conversion - added pragma …
Copilot Jul 20, 2025
9134e94
startasync
BrennanConroy Jul 21, 2025
f6c7ee3
convert
BrennanConroy Jul 21, 2025
161a1b5
Convert 12 more TestServerTests to HostBuilder pattern
Copilot Jul 22, 2025
5279775
testservertests
BrennanConroy Jul 23, 2025
ac08998
Update WebHostBuilder obsolete attribute to use ASPDEPR004 diagnostic ID
Copilot Jul 24, 2025
d63a4a8
Apply suggestions from code review
BrennanConroy Jul 24, 2025
c151d24
Update src/Hosting/TestHost/test/TestClientTests.cs
BrennanConroy Jul 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,12 @@ public async Task WebhostLoadsKeyRingBeforeServerStarts()
.Returns(Mock.Of<IKeyRing>())
.Callback(() => tcs.TrySetResult());

var builder = new WebHostBuilder()
.UseStartup<TestStartup>()
var builder = new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseStartup<TestStartup>();
})
.ConfigureServices(s =>
s.AddDataProtection()
.Services
Expand Down
3 changes: 3 additions & 0 deletions src/Hosting/Hosting/src/WebHostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ namespace Microsoft.AspNetCore.Hosting;
/// <summary>
/// A builder for <see cref="IWebHost"/>
/// </summary>
#pragma warning disable CS0618 // Type or member is obsolete
[Obsolete("TODO: Add Obsolete message")]
#pragma warning restore CS0618 // Type or member is obsolete
public class WebHostBuilder : IWebHostBuilder
{
private readonly HostingEnvironment _hostingEnvironment;
Expand Down
9 changes: 9 additions & 0 deletions src/Hosting/Hosting/test/WebHostBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ public void DoNotCaptureStartupErrorsByDefault(IWebHostBuilder builder)
public void ServiceProviderDisposedOnBuildException()
{
var service = new DisposableService();
#pragma warning disable CS0618 // Type or member is obsolete
var hostBuilder = new WebHostBuilder()
.UseServer(new TestServer())
.ConfigureServices(services =>
Expand All @@ -437,6 +438,7 @@ public void ServiceProviderDisposedOnBuildException()
services.AddSingleton(sp => service);
})
.UseStartup<StartupWithResolvedDisposableThatThrows>();
#pragma warning restore CS0618 // Type or member is obsolete

Assert.Throws<InvalidOperationException>(() => hostBuilder.Build());
Assert.True(service.Disposed);
Expand Down Expand Up @@ -1483,14 +1485,18 @@ private IWebHostBuilder CreateWebHostBuilder()
.AddInMemoryCollection(vals);
var config = builder.Build();

#pragma warning disable CS0618 // Type or member is obsolete
return new WebHostBuilder().UseConfiguration(config);
#pragma warning restore CS0618 // Type or member is obsolete
}

#pragma warning disable CS0618 // Type or member is obsolete
public static TheoryData<IWebHostBuilder> DefaultWebHostBuilders => new TheoryData<IWebHostBuilder>
{
new WebHostBuilder(),
new GenericWebHostBuilderWrapper(new HostBuilder())
};
#pragma warning restore CS0618 // Type or member is obsolete

public static TheoryData<IWebHostBuilder> DefaultWebHostBuildersWithConfig
{
Expand All @@ -1506,10 +1512,12 @@ public static TheoryData<IWebHostBuilder> DefaultWebHostBuildersWithConfig
.AddInMemoryCollection(vals);
var config = builder.Build();

#pragma warning disable CS0618 // Type or member is obsolete
return new TheoryData<IWebHostBuilder> {
new WebHostBuilder().UseConfiguration(config),
new GenericWebHostBuilderWrapper(new HostBuilder()).UseConfiguration(config)
};
#pragma warning restore CS0618 // Type or member is obsolete
}
}

Expand Down Expand Up @@ -1783,3 +1791,4 @@ public void Dispose()
public void AddProvider(ILoggerProvider provider) { }
}
}
//#pragma warning restore CS0618 // Type or member is obsolete
2 changes: 2 additions & 0 deletions src/Hosting/Hosting/test/WebHostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,9 @@ private IWebHost CreateHost(RequestDelegate requestDelegate)

private IWebHostBuilder CreateBuilder(IConfiguration config = null)
{
#pragma warning disable CS0618 // Type or member is obsolete
return new WebHostBuilder().UseConfiguration(config ?? new ConfigurationBuilder().Build()).UseStartup("Microsoft.AspNetCore.Hosting.Tests");
#pragma warning restore CS0618 // Type or member is obsolete
}

private static bool[] RegisterCallbacksThatThrow(IServiceCollection services)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<PropertyGroup>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<!-- CS0618: WebHostBuilder is obsolete -->
<NoWarn>$(NoWarn);CS0618</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

<PropertyGroup>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<!-- CS0618: WebHostBuilder is obsolete -->
<NoWarn>$(NoWarn);CS0618</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<PropertyGroup>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<OutputType>Exe</OutputType>
<!-- CS0618: WebHostBuilder is obsolete -->
<NoWarn>$(NoWarn);CS0618</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<PropertyGroup>
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
<OutputType>Exe</OutputType>
<!-- CS0618: WebHostBuilder is obsolete -->
<NoWarn>$(NoWarn);CS0618</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
20 changes: 14 additions & 6 deletions src/Identity/samples/IdentitySample.Mvc/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.IO;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;

namespace IdentitySample;

public static class Program
Expand All @@ -12,10 +16,14 @@ public static void Main(string[] args)
host.Run();
}

public static IWebHostBuilder CreateHostBuilder(string[] args) =>
new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>();
public static IHostBuilder CreateHostBuilder(string[] args) =>
new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>();
});
}
12 changes: 12 additions & 0 deletions src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,26 @@ public static int Main(string[] args)
return 12;
case "HangOnStop":
{
#pragma warning disable CS0618 // Type or member is obsolete
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This app explicitly targets 2.2 packages to make sure our IIS integration is backwards compatible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. I've kept the WebHostBuilder usage in InProcessWebSite/Program.cs with pragma disables since it explicitly targets 2.2 packages for backwards compatibility testing.

var host = new WebHostBuilder()
.UseIIS()
.UseStartup<Startup>()
.Build();
#pragma warning restore CS0618 // Type or member is obsolete
host.Run();

Thread.Sleep(Timeout.Infinite);
}
break;
case "IncreaseShutdownLimit":
{
#pragma warning disable CS0618 // Type or member is obsolete
var host = new WebHostBuilder()
.UseIIS()
.UseShutdownTimeout(TimeSpan.FromSeconds(120))
.UseStartup<Startup>()
.Build();
#pragma warning restore CS0618 // Type or member is obsolete

host.Run();
}
Expand All @@ -94,11 +98,13 @@ public static int Main(string[] args)
return 0;
case "OverriddenServer":
{
#pragma warning disable CS0618 // Type or member is obsolete
var host = new WebHostBuilder()
.UseIIS()
.ConfigureServices(services => services.AddSingleton<IServer, DummyServer>())
.Configure(builder => builder.Run(async context => { await context.Response.WriteAsync("I shouldn't work"); }))
.Build();
#pragma warning restore CS0618 // Type or member is obsolete
host.Run();
}
break;
Expand All @@ -111,6 +117,7 @@ public static int Main(string[] args)
#if !FORWARDCOMPAT
case "DecreaseRequestLimit":
{
#pragma warning disable CS0618 // Type or member is obsolete
var host = new WebHostBuilder()
.ConfigureLogging((_, factory) =>
{
Expand All @@ -124,13 +131,15 @@ public static int Main(string[] args)
})
.UseStartup<Startup>()
.Build();
#pragma warning restore CS0618 // Type or member is obsolete

host.Run();
break;
}
#endif
case "ThrowInStartup":
{
#pragma warning disable CS0618 // Type or member is obsolete
var host = new WebHostBuilder()
.ConfigureLogging((_, factory) =>
{
Expand All @@ -140,6 +149,7 @@ public static int Main(string[] args)
.UseIIS()
.UseStartup<ThrowingStartup>()
.Build();
#pragma warning restore CS0618 // Type or member is obsolete

host.Run();
}
Expand Down Expand Up @@ -189,6 +199,7 @@ public static int Main(string[] args)

private static int StartServer()
{
#pragma warning disable CS0618 // Type or member is obsolete
var host = new WebHostBuilder()
.ConfigureLogging((_, factory) =>
{
Expand All @@ -200,6 +211,7 @@ private static int StartServer()
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
#pragma warning restore CS0618 // Type or member is obsolete

host.Run();
return 0;
Expand Down
Loading
Loading