Fix --environment variables not applied to test process without launch profile#53306
Merged
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.
Youssef1313
approved these changes
Mar 6, 2026
Youssef1313
reviewed
Mar 6, 2026
Member
Youssef1313
left a comment
There was a problem hiding this comment.
We have a test RunTestProjectWithEnvVariable. We probably need to run it twice, once as-is and once with --no-launch-profile.
Contributor
There was a problem hiding this comment.
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
This was referenced May 25, 2026
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.
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 theif (Module.LaunchSettings is ProjectLaunchProfile)block. This meant that if:launchSettings.jsonexisted, or--no-launch-profilewas used...then
--environmentvariables were silently ignored and never set on the test process.This is inconsistent with
dotnet run, whereSetEnvironmentVariables()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