-
Notifications
You must be signed in to change notification settings - Fork 1.4k
*DO NOT MERGE* CmdLine parsing was extracted from XMake and the implementation is visible to dotnet (attempt 2) #12836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
*DO NOT MERGE* CmdLine parsing was extracted from XMake and the implementation is visible to dotnet (attempt 2) #12836
Conversation
There was a problem hiding this 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 conditional compilation constant, standardizing the codebase to consistently use string[] for command line arguments across both .NET Framework and .NET (Core). The change simplifies the codebase by eliminating platform-specific code paths that are no longer necessary since .NET supports string[] entry points directly.
Key changes:
- Added
BuildEnvironmentHelper.IsRunningOnCoreClrproperty to distinguish runtime types - Updated all public and internal APIs to accept
string[]instead of conditionally usingstringorstring[] - Modernized test code to use C# collection expressions (
[]instead ofnew[]) - Added API compatibility suppressions for experimental APIs that changed signatures
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Shared/BuildEnvironmentHelper.cs | Added IsRunningOnCoreClr property to detect .NET vs .NET Framework runtime |
| src/MSBuild/XMake.cs | Removed conditional compilation, standardized to string[] parameters, prepends executable path on CoreCLR |
| src/MSBuild/MSBuildClientApp.cs | Updated method signatures to consistently use string[] parameters |
| src/MSBuild.UnitTests/XMake_Tests.cs | Modernized tests to use collection expressions |
| src/MSBuild.UnitTests/ProjectSchemaValidationHandler_Tests.cs | Modernized tests to use collection expressions (with one interpolation bug) |
| src/MSBuild.UnitTests/CommandLineSwitches_Tests.cs | Modernized tests to use collection expressions |
| src/Directory.BeforeCommon.targets | Removed FEATURE_GET_COMMANDLINE constant definition |
| src/Build/CompatibilitySuppressions.xml | Added suppressions for breaking changes in experimental APIs |
| src/Build/BackEnd/Node/ServerNodeBuildCommand.cs | Updated command line field and constructor to use string[] |
| src/Build/BackEnd/Node/OutOfProcServerNode.cs | Updated BuildCallback delegate signature to accept string[] |
| src/Build/BackEnd/Client/MSBuildClient.cs | Updated constructor and internal logic to use string[] |
| src/Build.UnitTests/Utilities_Tests.cs | Modernized test to use collection expressions |
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
|
|
||
| private static readonly char[] s_commaSemicolon = { ',', ';' }; | ||
|
|
||
| private static CommandLineParser commandLineParser; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CommandLineParser can be instantiated, but XMake originally relied on static methods instead.
| public static int Main(string[] args) | ||
| { | ||
| // When running on CoreCLR(.NET), insert the command executable path as the first element of the args array. | ||
| args = BuildEnvironmentHelper.IsRunningOnCoreClr ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I retained the original logic that distinguishes between .NET and .NET Framework. Using Environment.CommandLine for both could produce unexpected results because of argument preprocessing in the SDK/CLI.
In the future, we can verify whether the .NET branch here is also applicable to .NET Framework.
|
|
||
| internal IReadOnlyList<string> IncludedResponseFiles => includedResponseFiles ?? (IReadOnlyList<string>)Array.Empty<string>(); | ||
|
|
||
| public (CommandLineSwitches commandLineSwitches, CommandLineSwitches responseFileSwitches) Parse(IEnumerable<string> commandLineArgs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a convenient method for external clients (like CLI) that do not need to handle fullCommandLine or exeName.
Fixes #839
Context
In some cases dotnet needs to process MSBuild command line switches including response files (.rsp).
Changes Made
FEATURE_GET_COMMANDLINEworkaround is no longer needed and it was removed. Parsing methods are now usingIEnumerable<string>instead ofstring. Parsing logic was extracted fromXMaketoCommandLineParserclass.Testing
All existing tests are passing.
TODO: VMR check is required
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.How to review
All commits except the last one was a preparation - removing
FEATURE_GET_COMMANDLINEconstant and migration to vector of strings in our implementations. Last commit extracts the parsing logic toCommandLineParserclass.