command-line-api icon indicating copy to clipboard operation
command-line-api copied to clipboard

How do you customize the --version flag?

Open 1ma opened this issue 3 years ago • 1 comments

The documentation mentions that System.CommandLine supports the --version flag out of the box but it doesn't show how to override its default value, and I cannot find any method on the RootCommand class to set it.

Side suggestion 1: Change the default value from 1.0.0 to 0.1.0. When an app follows semantic versioning its first release is usually very far from 1.0.

Side suggestion 2: Enable GitHub Discussions on the repo so that the community can ask ~obnoxious~ newbie questions like this one there and declutter the Issues section.

1ma avatar Mar 13 '22 21:03 1ma

The --version option has no built-in default value. The version value is coming straight from the entry assembly. The entry assembly is normally the executable built by your software project.

System.CommandLine looks for an AssemblyInformationalVersionAttribute on the entry assembly to get the version number. If the entry assembly is not annotated with this attribute, System.CommandLine will obtain the version value from the entry assembly's name (i.e., the value typically specified by the AssemblyVersionAttribute attribute). See the related System.CommandLine source here.

These assembly attributes can for example be set in the .csproj file (documentation: https://docs.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props#generateassemblyinfo).

elgonzo avatar Mar 14 '22 07:03 elgonzo