-
Notifications
You must be signed in to change notification settings - Fork 228
System.CommandLine - Change Terminating API to be callable from C# 7 #2359
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
System.CommandLine - Change Terminating API to be callable from C# 7 #2359
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
Updates the System.CommandLine library to make the CliAction.Terminating API callable from C# 7 by replacing the protected init accessor with a virtual property pattern, addressing compatibility issues with older language versions and Visual Studio versions.
Key Changes:
- Replaced
Terminating { get; protected init; }withvirtual bool Terminating => truein the baseCommandLineActionclass - Updated all implementing classes to override the
Terminatingproperty instead of setting it in constructors - Removed the protected init setter from the API compatibility approval tests
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| CommandLineAction.cs | Changed base class to use virtual property pattern for Terminating |
| Parser.cs | Updated PrintCliSchemaAction to override Terminating property |
| WorkloadCommandParser.cs | Updated workload action classes to override Terminating property |
| EnvironmentVariablesDirective.cs | Updated directive action to override Terminating property |
| TestActions.cs | Updated test action classes to override Terminating property |
| ApiCompatibilityApprovalTests.*.approved.txt | Removed the protected init setter from approved API surface |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
adamsitnik
left a comment
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.
LGTM, thank you @jonsequitur ! Is it the only init public property we have?
|
Are there any compensating changes needed elsewhere in the dotnet repo? (Based on this change, I assume not.) |
This is the only
The SDK changes included here are the only occurrences within dotnet/dotnet or that could be found across the dotnet org. |
|
/backport to release/10.0.1xx |
|
Started backporting to release/10.0.1xx: https://github.com/dotnet/dotnet/actions/runs/17653809677 |
Description
Fixes dotnet/command-line-api#2213 -
initaccessor of CliAction.Terminating cannot be called in C# 7Impact
The
initaccessor cannot be directly called in C# 7; it requires at least C# 9. That makes the property difficult to initialize in these cases:This issue was originally reported in 2023, but it had fallen off our radar. A customer commented on the issue last week bringing it back to our attention.
Details
This fix updates the
CommandLineAction.TerminatingAPI to be virtual rather than relying on theprotected initlanguage feature. This is a breaking change, and we are therefore applying to change via the dotnet/dotnet repo so the compensating changes to the SDK can be applied at the same time.Breaking Change?
Yes - but usage of this property is relatively low (SDK is the only impacted component in our product), and we want to get the API correct before stable release. We confirmed that neither the NuGet Client nor the new Microsoft/MCP repos utilize this API. NuGet does not have any subclasses of
CommandLineAction.Testing
Automated tests continue to preserve the existing functionality - this is mostly an API surface area change.