Skip to content

[release/10.0.4xx] Fix --environment variables not applied to test process without launch profile#54428

Open
Evangelink wants to merge 1 commit into
release/10.0.4xxfrom
dev/amauryleve/backport-pr-53306-to-10.0.4xx
Open

[release/10.0.4xx] Fix --environment variables not applied to test process without launch profile#54428
Evangelink wants to merge 1 commit into
release/10.0.4xxfrom
dev/amauryleve/backport-pr-53306-to-10.0.4xx

Conversation

@Evangelink
Copy link
Copy Markdown
Member

Backport of #53306 to release/10.0.4xx.

Customer Impact

Tests run via dotnet test -e NAME=VALUE / dotnet test --environment NAME=VALUE with the Microsoft.Testing.Platform runner do not see those environment variables when the test project has no launchSettings.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 if block so the command-line override loop runs unconditionally (matching dotnet run behavior in RunCommand.SetEnvironmentVariables).

Testing

Verified the bug reproduces on 10.0.204 with a project lacking launchSettings.json and xunit.v3.core.mtp-v2. With the fix applied (validated on main), -e vars reach the test process.

Fixes #54323 (on release/10.0.4xx).

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.
Copy link
Copy Markdown
Contributor

Copilot AI left a 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 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants