Skip to content

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

Draft
Evangelink wants to merge 1 commit intomainfrom
fix/test-env-vars-without-launch-profile
Draft

Fix --environment variables not applied to test process without launch profile#53306
Evangelink wants to merge 1 commit intomainfrom
fix/test-env-vars-without-launch-profile

Conversation

@Evangelink
Copy link
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
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.

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