Skip to content
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

[Breaking change]: WebApplicationBuilder gives ASPNET_-prefixed environment variables lower precedence #498

Open
1 of 3 tasks
halter73 opened this issue Nov 18, 2022 · 0 comments
Labels
7.0.0 Breaking change Documented The breaking change has been published to the .NET Core docs

Comments

@halter73
Copy link
Member

Description

Starting in .NET 7 preview 3, when using WebApplicationBuilder but not any other host (e.g. ConfigureWebHostDefaults or WebHost.CreateDefaultBuilder), command-line arguments and DOTNET_-prefixed environment variables override ASPNET_-prefixed environment variables when reading from default host configuration sources which are used to read host variables like the content root path and environment name when the WebApplicationBuilder is constructed and serves as a base for application configuration.

ASPNET_-prefixed environment variables now has the lowest precedence of all of WebApplicationBuilder's default host configuration sources.

See dotnet/AspNetCore.Docs#25626 (comment) for more context.

Version

.NET 7 Preview 3

Previous behavior

ASPNET_-prefixed environment variables overrode command-line arguments and DOTNET_-prefixed environment variables.

New behavior

Command-line arguments and DOTNET_-prefixed environment variables override ASPNET_-prefixed environment variables

Type of breaking change

  • Binary incompatible: Existing binaries may encounter a breaking change in behavior, such as failure to load/execute or different run-time behavior.
  • Source incompatible: Source code may encounter a breaking change in behavior when targeting the new runtime/component/SDK, such as compile errors or different run-time behavior.
  • Behavioral change: Existing code and binaries may experience different run-time behavior.

Reason for change

To prevent environment variables from overriding explicit command-line arguments when reading host variables which is more consistent with application configuration which has always given command-line arguments the highest precedence.

Recommended action

If you were using ASPNETCORE_-prefixed environment variables to override command-line arguments or DOTNET_-prefixed environment variables, use something with a higher priority. This could mean using custom WebApplicationOptions which overrides all default hosting configuration sources.

Affected APIs

Microsoft.AspNetCore.Builder.WebApplicationBuilder

@ghost ghost locked as resolved and limited conversation to collaborators Nov 18, 2022
@gewarren gewarren added the Documented The breaking change has been published to the .NET Core docs label Dec 3, 2022
@guardrex guardrex added the 7.0.0 label Nov 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
7.0.0 Breaking change Documented The breaking change has been published to the .NET Core docs
Projects
None yet
Development

No branches or pull requests

3 participants