Removing FEATURE_GET_COMMANDLINE constant#12693
Merged
MichalPavlik merged 4 commits intomainfrom Oct 24, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR removes the FEATURE_GET_COMMANDLINE preprocessor directive and associated workaround code, as .NET now natively supports Environment.CommandLine. The changes standardize command line handling to use string instead of string[] throughout the codebase, except for the Main entry point which still accepts string[] args for SDK compatibility.
Key Changes:
- Removed conditional compilation directives (
#if FEATURE_GET_COMMANDLINE) throughout the codebase - Standardized method signatures to accept
string commandLineinstead of conditionalstring[]orstringparameters - Updated MSBuildClient constructor to support backward compatibility with an obsolete overload
- Added compatibility suppressions for API changes in
OutOfProcServerNode.BuildCallback
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/MSBuild/XMake.cs | Removed conditional compilation and simplified method signatures to use Environment.CommandLine directly |
| src/MSBuild/MSBuildClientApp.cs | Updated Execute methods to use string commandLine parameter consistently |
| src/MSBuild.UnitTests/XMake_Tests.cs | Simplified test calls to use string command line format |
| src/MSBuild.UnitTests/CommandLineSwitches_Tests.cs | Updated test to use string command line format |
| src/Directory.BeforeCommon.targets | Removed FEATURE_GET_COMMANDLINE constant definition |
| src/Build/CompatibilitySuppressions.xml | Added suppressions for BuildCallback API changes |
| src/Build/BackEnd/Node/ServerNodeBuildCommand.cs | Changed CommandLine property from conditional type to string |
| src/Build/BackEnd/Node/OutOfProcServerNode.cs | Updated BuildCallback delegate signature to use string |
| src/Build/BackEnd/Client/MSBuildClient.cs | Added obsolete constructor overload and simplified parameter handling |
| src/Build.UnitTests/Utilities_Tests.cs | Updated test to use string command line format |
rainersigwald
approved these changes
Oct 23, 2025
JanProvaznik
approved these changes
Oct 24, 2025
This was referenced Oct 24, 2025
Member
#!/bin/bash
# Usage: ./repro.sh [path_to_dotnet_executable]
DOTNET="${1:-dotnet}"
WORK_DIR="msbuild_repro_temp"
# cleanup function
cleanup() {
rm -rf "$WORK_DIR"
}
trap cleanup EXIT
# Create a clean workspace
rm -rf "$WORK_DIR"
mkdir "$WORK_DIR"
cd "$WORK_DIR"
# 1. Create a minimal valid project file
cat > repro.proj <<EOF
<Project>
<Target Name="Build">
<Message Text="Build Succeeded!" Importance="High" />
</Target>
</Project>
EOF
echo "--------------------------------------------------------"
echo "Running reproduction with: $DOTNET"
echo "Command: dotnet build (implicit project)"
echo "--------------------------------------------------------"
# 2. Run the build without arguments.
# The dotnet host creates the arguments, but the bug reads the raw command line.
OUTPUT=$("$DOTNET" build 2>&1)
EXIT_CODE=$?
echo "$OUTPUT"
echo "--------------------------------------------------------"
# 3. Analyze Results
if [ $EXIT_CODE -eq 0 ]; then
echo "✅ PASS: Build succeeded. Arguments were parsed correctly."
exit 0
else
# We look for:
# 1. MSB1009 (Project not found) - Specifically looking for file 'build'
# 2. MSB1008 (Multiple projects) - If it picked up repro.proj AND 'build'
if echo "$OUTPUT" | grep -q "Switch: build"; then
echo "❌ FAIL: Regression detected."
echo "Reason: MSBuild read the raw command line and interpreted the verb 'build' as a project file."
exit 1
else
echo "⚠️ FAIL: Build failed, but the output does not explicitly show 'Switch: build'."
exit 1
fi
firegression reproduction, passes on net 8 dotnet, fails on bootstrapped main dotnet |
JanProvaznik
added a commit
to JanProvaznik/msbuild
that referenced
this pull request
Nov 19, 2025
This reverts commit 60fc61c.
YuliiaKovalova
pushed a commit
that referenced
this pull request
Nov 20, 2025
reverts #12693 #12704 ### Context unblocking VMR insertion dotnet/dotnet#3091 ### Changes Made ### Testing ### Notes
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.
Fixes #839
Context
FEATURE_GET_COMMANDLINE workaround is no longer needed as .NET supports
Environment.CommandLine.Changes Made
Removed all code that consumes args as
string[]except entry point that is used by SDK.Testing
All existing tests are passing.
Notes
MSBuildClientshouldn't be used outside MSBuild.OutOfProcServerNode.BuildCallbackdelegate shouldn't be used anywhere. This delegate (and whole type) are public just because we are not able to expose internal types with MSBuild project due to shared sources in both projects. We had to useExperimentalnamespace instead.