Skip to content

Removing FEATURE_GET_COMMANDLINE constant#12693

Merged
MichalPavlik merged 4 commits intomainfrom
dev/mipavlik/remove-feature-get-commandline-flag
Oct 24, 2025
Merged

Removing FEATURE_GET_COMMANDLINE constant#12693
MichalPavlik merged 4 commits intomainfrom
dev/mipavlik/remove-feature-get-commandline-flag

Conversation

@MichalPavlik
Copy link
Copy Markdown
Member

@MichalPavlik MichalPavlik commented Oct 23, 2025

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

MSBuildClient shouldn't be used outside MSBuild.

OutOfProcServerNode.BuildCallback delegate 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 use Experimental namespace instead.

Copilot AI review requested due to automatic review settings October 23, 2025 12:27
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 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 commandLine instead of conditional string[] or string parameters
  • 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

Comment thread src/Build/BackEnd/Client/MSBuildClient.cs Outdated
Comment thread src/MSBuild/XMake.cs
@MichalPavlik MichalPavlik self-assigned this Oct 23, 2025
Comment thread src/Build/CompatibilitySuppressions.xml
Comment thread src/Build/BackEnd/Client/MSBuildClient.cs
Comment thread src/Build/BackEnd/Client/MSBuildClient.cs Outdated
Copy link
Copy Markdown
Member

@JanProvaznik JanProvaznik left a comment

Choose a reason for hiding this comment

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

:shipit: assuming Rainer agrees

Comment thread src/Build/BackEnd/Node/ServerNodeBuildCommand.cs Outdated
@JanProvaznik
Copy link
Copy Markdown
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
fi

regression 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
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
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.

Simplify back to Environment.GetCommandLineArgs

4 participants