aspnetcore/breaking-changes/7/environment-variable-precedence.md
Starting in .NET 7, and only when using the WebApplicationBuilder host, command-line arguments and DOTNET_-prefixed environment variables override ASPNET_-prefixed environment variables when reading from default host configuration sources. These sources are used to read host variables, such as the content root path and environment name, when the WebApplicationBuilder is constructed and serve as a base for app configuration.
ASPNET_-prefixed environment variables now have the lowest precedence of all of the default host configuration sources for WebApplicationBuilder. For other hosts, such as ConfigureWebHostDefaults and WebHost.CreateDefaultBuilder, ASPNET_-prefixed environment variables still have the highest precedence.
ASP.NET Core 7.0
ASPNET_-prefixed environment variables overrode command-line arguments and DOTNET_-prefixed environment variables when reading WebApplicationBuilder's default host configuration.
Command-line arguments and DOTNET_-prefixed environment variables override ASPNET_-prefixed environment variables when reading WebApplicationBuilder's default host configuration.
This is a behavioral change.
This change was made to prevent environment variables from overriding explicit command-line arguments when reading host variables. The new behavior is more consistent with application configuration, which has always given command-line arguments the highest precedence.
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 xref:Microsoft.AspNetCore.Builder.WebApplicationOptions, which overrides all default hosting configuration sources.