Skip to content
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

VersionOptionFromAssemblyAttributes - no documentation for template #535

Closed
digitaldias opened this issue Jun 11, 2023 · 3 comments
Closed
Labels
closed-stale This issue is closed because it went stale and there was no action planned. It can be reopened. question stale

Comments

@digitaldias
Copy link

I'm setting up a small app and wanted to customize the version string returned by --version.
I need help finding where in the documentation the template argument's content should look like.
Currently, I have this:

app.VersionOptionFromAssemblyAttributes("", Assembly.GetExecutingAssembly());

Which, of course, won't work! :)

Can someone please advise?

@natemcmaster
Copy link
Owner

Checkout how app.VersionOptionFromAssemblyAttributes is implemented. It's a helper method that just calls .VersionOption. If you want to customize things, use .VersionOption instead

/// <summary>
/// Finds <see cref="AssemblyInformationalVersionAttribute"/> on <paramref name="assembly"/> and uses that
/// to set <see cref="CommandLineApplication.OptionVersion"/>.
/// <para>
/// Uses the Version that is part of the <see cref="AssemblyName"/> of the specified assembly
/// if no <see cref="AssemblyInformationalVersionAttribute"/> is applied.
/// </para>
/// </summary>
/// <param name="app"></param>
/// <param name="assembly"></param>
/// <exception cref="ArgumentNullException">Either <paramref name="app"/> or <paramref name="assembly"/> is <c>null</c>.</exception>
public static CommandOption VersionOptionFromAssemblyAttributes(this CommandLineApplication app, Assembly assembly)
=> VersionOptionFromAssemblyAttributes(app, Strings.DefaultVersionTemplate, assembly);
/// <summary>
/// Finds <see cref="AssemblyInformationalVersionAttribute"/> on <paramref name="assembly"/> and uses that
/// to set <see cref="CommandLineApplication.OptionVersion"/>.
/// <para>
/// Uses the Version that is part of the <see cref="AssemblyName"/> of the specified assembly
/// if no <see cref="AssemblyInformationalVersionAttribute"/> is applied.
/// </para>
/// </summary>
/// <param name="app"></param>
/// <param name="template"></param>
/// <param name="assembly"></param>
/// <exception cref="ArgumentNullException">Either <paramref name="app"/> or <paramref name="assembly"/> is <c>null</c>.</exception>
public static CommandOption VersionOptionFromAssemblyAttributes(this CommandLineApplication app, string template, Assembly assembly)
=> app.VersionOption(template, GetInformationalVersion(assembly));
private static string? GetInformationalVersion(Assembly assembly)
{
var infoVersion = assembly
?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
?.InformationalVersion;
return string.IsNullOrWhiteSpace(infoVersion)
? assembly?.GetName().Version.ToString()
: infoVersion;
}

Copy link

This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please comment if you believe this should remain open, otherwise it will be closed in 14 days. Thank you for your contributions to this project.

@github-actions github-actions bot added the stale label Jun 25, 2024
Copy link

github-actions bot commented Jul 9, 2024

Closing due to inactivity.
If you are looking at this issue in the future and think it should be reopened, please make a commented here and mention natemcmaster so he sees the notification.

@github-actions github-actions bot added the closed-stale This issue is closed because it went stale and there was no action planned. It can be reopened. label Jul 9, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-stale This issue is closed because it went stale and there was no action planned. It can be reopened. question stale
Projects
None yet
Development

No branches or pull requests

2 participants