-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add environment variables to IConfiguration by default in WebAssemblyHostBuilder #64578
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! 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! |
…HostBuilder Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
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.
Pull request overview
This PR adds environment variables to IConfiguration by default in WebAssemblyHostBuilder.CreateDefault(), aligning WebAssembly behavior with server-side ASP.NET Core applications. This enables Aspire integration scenarios where Service Discovery and OpenTelemetry configuration need to read from IConfiguration.
Key changes:
- Environment variables are now automatically available in
IConfigurationviaCreateDefault() - Eliminates the need for developers to manually call
AddEnvironmentVariables() - Enables Aspire integration to work out-of-the-box
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| WebAssemblyHostBuilder.cs | Adds AddEnvironmentVariables() call in CreateDefault() method |
| Microsoft.AspNetCore.Components.WebAssembly.csproj | Adds package reference to Microsoft.Extensions.Configuration.EnvironmentVariables |
| WebAssemblyHostBuilderTest.cs | Adds test to verify environment variables are accessible through IConfiguration |
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
Add environment variables to IConfiguration by default in WebAssemblyHostBuilder
Add environment variables to IConfiguration by default in WebAssemblyHostBuilder.CreateDefault()
Description
Environment variables injected via
MonoConfig.environmentVariablesare available throughEnvironment.GetEnvironmentVariable()but not inIConfiguration. This blocks Aspire integration since Service Discovery and OpenTelemetry read fromIConfiguration.Changes:
Microsoft.Extensions.Configuration.EnvironmentVariablespackage referencebuilder.Configuration.AddEnvironmentVariables()inCreateDefault()Before (workaround required):
After:
Aligns WebAssembly behavior with server-side
WebApplication.CreateBuilder().Fixes ##64576
Original prompt
💡 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.