Skip to content

Conversation

@jonsequitur
Copy link
Contributor

@jonsequitur jonsequitur commented Sep 10, 2025

Description

Fixes dotnet/command-line-api#2213 - init accessor of CliAction.Terminating cannot be called in C# 7

Impact

The init accessor 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.Terminating API to be virtual rather than relying on the protected init language 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.

@jeffhandley jeffhandley changed the title fix https://github.com/dotnet/command-line-api/issues/2213 System.CommandLine - Change Terminating API to be callable from C# 7 Sep 11, 2025
@jeffhandley jeffhandley requested a review from Copilot September 11, 2025 07:34
Copy link
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

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; } with virtual bool Terminating => true in the base CommandLineAction class
  • Updated all implementing classes to override the Terminating property 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.

Copy link
Member

@adamsitnik adamsitnik left a 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?

@jeffhandley jeffhandley requested a review from artl93 September 11, 2025 16:35
@artl93
Copy link
Member

artl93 commented Sep 11, 2025

Are there any compensating changes needed elsewhere in the dotnet repo? (Based on this change, I assume not.)

@jeffhandley
Copy link
Member

LGTM, thank you @jonsequitur ! Is it the only init public property we have?

This is the only init property we had.

Are there any compensating changes needed elsewhere in the dotnet repo?

The SDK changes included here are the only occurrences within dotnet/dotnet or that could be found across the dotnet org.

@jeffhandley jeffhandley added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Sep 11, 2025
@jeffhandley jeffhandley merged commit 58edc73 into dotnet:main Sep 11, 2025
11 checks passed
@jeffhandley
Copy link
Member

/backport to release/10.0.1xx

@github-actions
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Servicing-approved Approved for servicing release

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

init accessor of CliAction.Terminating cannot be called in C# 7

5 participants