-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Mark WebHostBuilder class as obsolete #62785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
There are a few places that we should update from WebHostBuilder to HostBuilder Below is an example of what the transformation looks like // Before // After |
Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Updated all four files to use HostBuilder instead of WebHostBuilder following your example pattern. All instances have been converted to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a pragma disable for webhost.cs
Also update src\Identity\samples\IdentitySample.Mvc\Program.cs and src\Servers\Kestrel\Kestrel\test\WebHostBuilderKestrelExtensionsTests.cs to HostBuilder
src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Program.cs
Outdated
Show resolved
Hide resolved
…r pattern Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Added pragma disable for WebHostBuilder.cs and updated both IdentitySample.Mvc/Program.cs and WebHostBuilderKestrelExtensionsTests.cs to use HostBuilder pattern as requested. (5407fb0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add pragma warning to src/DefaultBuilder/src/WebHost.cs(157,27)
…Builder.cs Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Added pragma warning suppression around the WebHostBuilder instantiation in WebHost.cs CreateDefaultBuilder method. (dd80d9c) |
Could you update src/SignalR/clients/csharp/Client/test/UnitTests/TestServerTests.cs and src/Servers/Kestrel/Kestrel/test/HttpsConfigurationTests.cs to HostBuilder |
…uilder pattern Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Updated both TestServerTests.cs and HttpsConfigurationTests.cs to use HostBuilder pattern as requested. The SignalR TestServerTests are now passing with the proper HostBuilder.ConfigureWebHost pattern. The Kestrel HttpsConfigurationTests have been converted but some test adjustments may be needed for the new hosting model. (3f16853) Warning Firewall rules blocked me from connecting to one or more addressesI tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
@@ -2,6 +2,8 @@ | |||
|
|||
<PropertyGroup> | |||
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework> | |||
<!-- CS0618: WebHostBuilder is obsolete --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove these nowarn settings that were added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the nowarn settings from the 4 project files as requested. Started converting TestHost test files to HostBuilder pattern (completed WebSocketClientTests). The remaining TestHost test files have 70+ WebHostBuilder usages that need conversion - working through them systematically. (194d366)
…lder pattern Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
…ebSocketClientTests to HostBuilder Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Can you update src/Hosting/TestHost/test/TestClientTests.cs src/Hosting/TestHost/test/TestServerTests.cs and src/Hosting/TestHost/test/HttpContextBuilderTests.cs to use HostBuilder |
Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
I've started converting the TestHost test files to HostBuilder pattern as requested. Completed HttpContextBuilderTests.cs conversion (b146f4d). The pattern follows the established approach from WebSocketClientTests.cs: using var host = new HostBuilder()
.ConfigureWebHost(webBuilder =>
{
webBuilder
.UseTestServer()
.Configure(app => { });
})
.Build();
var server = host.GetTestServer(); Currently working on TestClientTests.cs and TestServerTests.cs - these files have 26 and 29 WebHostBuilder instances respectively that need conversion. The conversion is in progress. |
…stBuilder Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Fixes #20964
This PR marks the
WebHostBuilder
class as obsolete using the[Obsolete]
attribute with a placeholder message as requested in issue #20964.Changes Made
[Obsolete("TODO: Add Obsolete message")]
attribute to theWebHostBuilder
class declarationNoWarn
property:Microsoft.AspNetCore.Hosting.Tests.csproj
Microsoft.AspNetCore.TestHost.Tests.csproj
Microsoft.AspNetCore.Hosting.WindowsServices.Tests.csproj
IStartupInjectionAssemblyName.csproj
Microsoft.AspNetCore.Hosting.TestSites.csproj
Rationale
The
WebHostBuilder
class was replaced byHostBuilder
in ASP.NET Core 3.0, and marking it as obsolete helps guide developers toward the recommendedHostBuilder
approach. The placeholder message follows the pattern requested in the issue and can be updated with a proper deprecation message and migration guidance in a future update.Testing
WebHostBuilder
in projects that don't suppress CS0618This is a minimal, non-breaking change that maintains backward compatibility while alerting developers to the obsolete status of
WebHostBuilder
.This pull request was created as a result of the following prompt from Copilot chat.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.