Skip to content

Fix --environment variables not applied to test process without launch profile#53306

Merged
Evangelink merged 2 commits into
mainfrom
fix/test-env-vars-without-launch-profile
May 19, 2026
Merged

Fix --environment variables not applied to test process without launch profile#53306
Evangelink merged 2 commits into
mainfrom
fix/test-env-vars-without-launch-profile

Conversation

@Evangelink
Copy link
Copy Markdown
Member

Summary

Fixes environment variables specified via --environment (-e) not being applied to test processes when no launch profile is present.

Problem

In TestApplication.CreateProcessStartInfo(), the loop that applies command-line environment variables was inside the if (Module.LaunchSettings is ProjectLaunchProfile) block. This meant that if:

  • No launchSettings.json existed, or
  • --no-launch-profile was used

...then --environment variables were silently ignored and never set on the test process.

This is inconsistent with dotnet run, where SetEnvironmentVariables() always applies command-line env vars regardless of whether a launch profile is present (RunCommand.cs).

Fix

Move the command-line env var loop outside of the launch profile block. Command-line vars still override launch profile vars when both are present (they are applied after launch profile vars).

Changes

  • src/Cli/dotnet/Commands/Test/MTP/TestApplication.cs

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
Member

@Youssef1313 Youssef1313 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a test RunTestProjectWithEnvVariable. We probably need to run it twice, once as-is and once with --no-launch-profile.

@Evangelink Evangelink marked this pull request as ready for review May 18, 2026 17:06
Copilot AI review requested due to automatic review settings May 18, 2026 17:06
@Evangelink Evangelink requested a review from a team as a code owner May 18, 2026 17:06
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

Fixes dotnet test (MTP) so environment variables passed via --environment/-e are applied to the test process even when no launch profile is used (e.g., missing launchSettings.json or --no-launch-profile).

Changes:

  • Move command-line environment-variable application out of the launch-profile-only block in TestApplication.CreateProcessStartInfo().
  • Preserve precedence: command-line variables are applied after launch profile variables (when present).
Show a summary per file
File Description
src/Cli/dotnet/Commands/Test/MTP/TestApplication.cs Ensures --environment variables are always applied to the spawned test process, independent of launch profile availability.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment thread src/Cli/dotnet/Commands/Test/MTP/TestApplication.cs
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.

3 participants