-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Add [Obsolete] attribute to WebHost class and IWebHost interface, convert sample apps to HostBuilder pattern #63024
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
Greetings human! You've submitted a PR that modifies code that is shared with https://github.com/dotnet/runtime . Please make sure you synchronize this code with the changes in that repo! |
Co-authored-by: BrennanConroy <[email protected]>
…warning suppressions Co-authored-by: BrennanConroy <[email protected]>
You're absolutely right! I applied the [Obsolete] attribute to the correct WebHost class in |
@copilot can you convert the sample apps to HostBuilder? Before: public static void Main(string[] args)
{
CreateWebHostBuilder(args).Build().Run();
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>(); After: public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
}); |
Co-authored-by: BrennanConroy <[email protected]>
... I've converted 12 sample apps from the WebHost.CreateDefaultBuilder pattern to the Host.CreateDefaultBuilder pattern as requested. The conversion follows the exact pattern you provided: Converted files:
Pattern applied:
All builds and tests pass successfully. (commit ac4fcb6) |
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.
@copilot let's mark IWebHost as obsolete now
#pragma warning disable CS0618 // Type or member 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.
#pragma warning disable CS0618 // Type or member 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.
Removed the unnecessary #pragma warning disable CS0618
suppression since this test asset now uses the modern HostBuilder pattern and no longer needs to suppress obsolete warnings. (commit 410ec79)
#pragma warning disable CS0618 // Type or member 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.
#pragma warning disable CS0618 // Type or member 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.
Removed the unnecessary #pragma warning disable CS0618
suppression since this test asset now uses the modern HostBuilder pattern and no longer needs to suppress obsolete warnings. (commit 410ec79)
#pragma warning disable CS0618 // Type or member 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.
#pragma warning disable CS0618 // Type or member 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.
Removed the unnecessary #pragma warning disable CS0618
suppression since this test asset now uses the modern HostBuilder pattern and no longer needs to suppress obsolete warnings. (commit 410ec79)
Co-authored-by: BrennanConroy <[email protected]>
I've marked the |
This PR adds the
[Obsolete]
attribute to both theWebHost
class andIWebHost
interface in the ASP.NET Core hosting abstractions to indicate that they are obsolete and guide developers toward usingHostBuilder
orWebApplicationBuilder
instead. Additionally, it converts sample applications from the deprecated WebHost pattern to the recommended HostBuilder pattern.Changes
WebHost and IWebHost Obsolescence:
[Obsolete("WebHost is obsolete. Use HostBuilder or WebApplicationBuilder instead.")]
attribute to the public staticWebHost
class declaration[Obsolete("IWebHost is obsolete. Use IHost instead.")]
attribute to theIWebHost
interface declaration#pragma warning disable CS0618
) to 15+ internal framework files that need to continue using these obsolete APIs for backward compatibility, including:Sample App Modernization:
WebHost.CreateDefaultBuilder
pattern toHost.CreateDefaultBuilder
pattern:Pattern transformation applied:
Verification
warning CS0618: 'WebHost' is obsolete: 'WebHost is obsolete. Use HostBuilder or WebApplicationBuilder instead.'
warning CS0618: 'IWebHost' is obsolete: 'IWebHost is obsolete. Use IHost instead.'
This change provides clear migration guidance to developers while maintaining backward compatibility for existing code that relies on the
WebHost
andIWebHost
implementations.💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.