cli in c# How to catch an error of a required option

מממם 0 Reputation points
2023-12-11T19:53:39.45+00:00
    var languageOption = new Option<string>("--language", "file path and name") { IsRequired = true };

אז איך אני עושה שאם המשתמש לא מקיש את השפה זה לא יזרוק לן הודעת שגיאה ברירת מחדל אלא הודעת שגיאה שאני אחליט 


.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
323 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,277 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Jiachen Li-MSFT 26,671 Reputation points Microsoft Vendor
    2023-12-12T09:32:35.65+00:00

    Hi @מממם ,

    If you set the option IsRequired = true, the default error "Option '--language' is required" is always triggered first.

    If you want to display your own error message, you can instead set it to required, but manually determine whether it is empty in your code and output the error message.

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments