[release/10.0.4xx] Fix --environment variables not applied to test process without launch profile#54428
Open
Evangelink wants to merge 1 commit into
Open
Conversation
Environment variables specified via --environment (-e) on the command line were only applied when a launch profile was present. If no launch profile existed (or --no-launch-profile was used), the variables were silently ignored. Move the command-line env var loop outside of the launch profile block, matching the behavior of 'dotnet run' which always applies command-line env vars regardless of launch profile presence. The command-line vars still override launch profile vars when both are present.
Contributor
There was a problem hiding this comment.
Pull request overview
This backport fixes dotnet test (Microsoft.Testing.Platform runner) so environment variables provided via --environment/-e are applied to the test process even when no launchSettings.json / launch profile is present, addressing #54323 on release/10.0.4xx.
Changes:
- Apply command-line environment variables unconditionally in
TestApplication.CreateProcessStartInfo(). - Preserve precedence where command-line variables override launch-profile variables when both are present.
Show a summary per file
| File | Description |
|---|---|
| src/Cli/dotnet/Commands/Test/MTP/TestApplication.cs | Moves application of --environment/-e variables outside the launch-profile-only block so they always reach the spawned test process. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 1
Comment on lines
+156
to
+160
| // Env variables specified on command line override those specified in launch profile: | ||
| foreach (var (name, value) in TestOptions.EnvironmentVariables) | ||
| { | ||
| processStartInfo.Environment[name] = value; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #53306 to
release/10.0.4xx.Customer Impact
Tests run via
dotnet test -e NAME=VALUE/dotnet test --environment NAME=VALUEwith the Microsoft.Testing.Platform runner do not see those environment variables when the test project has nolaunchSettings.json. The CLI accepts and silently drops them. Reported in #54323.Regression?
No — the option was added in #50810 (10.0.2xx); it never worked without a launch profile.
Risk
Very low. Single-file change moving 6 lines out of an
ifblock so the command-line override loop runs unconditionally (matchingdotnet runbehavior inRunCommand.SetEnvironmentVariables).Testing
Verified the bug reproduces on 10.0.204 with a project lacking
launchSettings.jsonandxunit.v3.core.mtp-v2. With the fix applied (validated onmain),-evars reach the test process.Fixes #54323 (on
release/10.0.4xx).