Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Copilot wants to merge14 commits intomain
base:main
Choose a base branch
Loading
fromcopilot/fix-33c08791-0d71-4418-a169-d65989144212

Conversation

Copilot
Copy link
Contributor

@CopilotCopilotAI commentedJul 17, 2025
edited
Loading

Fixes#20964

This PR marks theWebHostBuilder class as obsolete using the[Obsolete] attribute with a placeholder message as requested in issue#20964.

Changes Made

  • Added[Obsolete("TODO: Add Obsolete message")] attribute to theWebHostBuilder class declaration
  • Updated 5 test project files to suppress CS0618 warnings by adding it to theNoWarn 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

TheWebHostBuilder 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

  • All existing tests continue to pass
  • The obsolete warning is properly generated when usingWebHostBuilder in projects that don't suppress CS0618
  • Test projects can still test the obsolete functionality by suppressing the warning at the project level

This is a minimal, non-breaking change that maintains backward compatibility while alerting developers to the obsolete status ofWebHostBuilder.

This pull request was created as a result of the following prompt from Copilot chat.

Mark the WebHostBuilder class as obsolete by adding the [Obsolete] attribute to its definition, using the placeholder message "TODO: Add Obsolete message". Do not change any other functionality. This implements the request from issue#20964 (#20964).


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Clickhere to start the survey.

Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
@CopilotCopilotAI changed the title[WIP] Mark WebHostBuilder as obsolete with placeholder messageMark WebHostBuilder class as obsoleteJul 17, 2025
@CopilotCopilotAI requested a review fromBrennanConroyJuly 17, 2025 18:43
Copilot finished work on behalf ofBrennanConroyJuly 17, 2025 18:43
@BrennanConroy
Copy link
Member

There are a few places that we should update from WebHostBuilder to HostBuilder
src\DataProtection\DataProtection\test\Microsoft.AspNetCore.DataProtection.Tests\HostingTests.cs
src\Servers\testassets\ServerComparison.TestSites\Program.cs
src\Servers\IIS\IIS\test\testassets\InProcessWebSite\Program.cs
src\Servers\Kestrel\test\Interop.FunctionalTests\Http3\Http3TlsTests.cs

Below is an example of what the transformation looks like

// Before
var host = new WebHostBuilder()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup()
.UseKestrel()
.Build();

// After
using var host = new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
{
webHostBuilder
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup()
.UseKestrel();
})
.Build();

Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
@CopilotCopilot SWE Agent
Copy link
ContributorAuthor

There are a few places that we should update from WebHostBuilder to HostBuilder
src\DataProtection\DataProtection\test\Microsoft.AspNetCore.DataProtection.Tests\HostingTests.cs
src\Servers\testasset...

Updated all four files to use HostBuilder instead of WebHostBuilder following your example pattern. All instances have been converted to usenew HostBuilder().ConfigureWebHost() with the WebHostBuilder configuration moved inside the callback. Fixed configuration access in ServerComparison.TestSites to use IConfiguration directly. (8c3f586)

Copilot finished work on behalf ofBrennanConroyJuly 17, 2025 19:54
Copy link
Member

@BrennanConroyBrennanConroy left a 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

…r patternCo-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
@CopilotCopilot SWE Agent
Copy link
ContributorAuthor

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

Added pragma disable for WebHostBuilder.cs and updated both IdentitySample.Mvc/Program.cs and WebHostBuilderKestrelExtensionsTests.cs to use HostBuilder pattern as requested. (5407fb0)

@CopilotCopilotAI requested a review fromBrennanConroyJuly 17, 2025 21:58
Copilot finished work on behalf ofBrennanConroyJuly 17, 2025 21:58
Copy link
Member

@BrennanConroyBrennanConroy left a 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.csCo-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
@CopilotCopilot SWE Agent
Copy link
ContributorAuthor

Add pragma warning to src/DefaultBuilder/src/WebHost.cs(157,27)

Added pragma warning suppression around the WebHostBuilder instantiation in WebHost.cs CreateDefaultBuilder method. (dd80d9c)

Copilot finished work on behalf ofBrennanConroyJuly 17, 2025 22:19
@CopilotCopilotAI requested a review fromBrennanConroyJuly 17, 2025 22:19
@BrennanConroy
Copy link
Member

Could you update src/SignalR/clients/csharp/Client/test/UnitTests/TestServerTests.cs and src/Servers/Kestrel/Kestrel/test/HttpsConfigurationTests.cs to HostBuilder

…uilder patternCo-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
@CopilotCopilot SWE Agent
Copy link
ContributorAuthor

CopilotAI commentedJul 17, 2025
edited
Loading

Could you update src/SignalR/clients/csharp/Client/test/UnitTests/TestServerTests.cs and src/Servers/Kestrel/Kestrel/test/HttpsConfigurationTests.cs to HostBuilder

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 addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • fakeurl.org
    • Triggering command:/home/REDACTED/work/aspnetcore/aspnetcore/.dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/aspnetcore/aspnetcore/artifacts/bin/Microsoft.AspNetCore.SignalR.Client.Tests/Debug/net10.0/Microsoft.AspNetCore.SignalR.Client.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/aspnetcore/aspnetcore/artifacts/bin/Microsoft.AspNetCore.SignalR.Client.Tests/Debug/net10.0/Microsoft.AspNetCore.SignalR.Client.Tests.deps.json /home/REDACTED/work/aspnetcore/aspnetcore/artifacts/bin/Microsoft.AspNetCore.SignalR.Client.Tests/Debug/net10.0/testhost.dll --port 32829 --endpoint 127.0.0.1:032829 --role client --parentprocessid 28228 --telemetryoptedin false (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf ofBrennanConroyJuly 17, 2025 22:57
@@ -2,6 +2,8 @@

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

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

Copy link
ContributorAuthor

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)

CopilotAIand others added2 commitsJuly 18, 2025 21:59
…lder patternCo-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
…ebSocketClientTests to HostBuilderCo-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
@BrennanConroy
Copy link
Member

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

CopilotAIand others added2 commitsJuly 19, 2025 00:24
Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Co-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
@CopilotCopilot SWE Agent
Copy link
ContributorAuthor

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

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:

usingvarhost=newHostBuilder().ConfigureWebHost(webBuilder=>{webBuilder.UseTestServer().Configure(app=>{});}).Build();varserver=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.

…stBuilderCo-authored-by: BrennanConroy <7574801+BrennanConroy@users.noreply.github.com>
Copilot finished work on behalf ofBrennanConroyJuly 19, 2025 00:30
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@BrennanConroyBrennanConroyAwaiting requested review from BrennanConroyBrennanConroy is a code owner

@halter73halter73Awaiting requested review from halter73halter73 will be requested when the pull request is marked ready for reviewhalter73 is a code owner

@JamesNKJamesNKAwaiting requested review from JamesNKJamesNK will be requested when the pull request is marked ready for reviewJamesNK is a code owner

At least 1 approving review is required to merge this pull request.

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Obsolete WebHostBuilder
2 participants
@Copilot@BrennanConroy

[8]ページ先頭

©2009-2025 Movatter.jp