microsoft / microsoft/WindowsAppSDK
Environment variables set in launchSettings.json are not used in Packaged app
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 4.7k
- Forks
- 471
- Avg merge
- 3d 13h
- Merged PRs (30d)
- 28
Description
Describe the bug
I want to use the Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder() to host a WinUI application. This works fine and I store basic configuration in the appsettings.json.
However if I want to set the environment via an environment variable in the launchSettings.json as described here it does not work as the environment variables are not set when starting the packaged profile.
Steps to reproduce the bug
- Create a blank WinUi 3 app in VS2022
- alter the launchSettings.json to include some environment variables in the section for the "Package" profile.
"Sample.Winui (Packaged)": { "commandName": "MsixPackage", "environmentVariables": { "DOTNET_ENVIRONMENT": "Development" } } - Add
var temp = Environment.GetEnvironmentVariables()in the constructor of the App class - Set a breakpoint after the statement and review the contents of
tempto look for the environment variable
Expected behavior
The environment variables should be set when running the packaged app from within visual studio.
Screenshots
No response
NuGet package version
Windows App SDK 1.3.0: 1.3.230331000
Packaging type
Packaged (MSIX)
Windows version
Windows 10 version 22H2 (19045, 2022 Update)
IDE
Visual Studio 2022
Additional context
No response
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the packaged WinUI app from Visual Studio using the launchSettings.json Package profile and inspect Environment.GetEnvironmentVariables() in the App constructor. Compare the packaged profile behavior with the expected DOTNET_ENVIRONMENT value; done means the configured environment variables are present when the packaged app starts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100