Reputation: 1342
I can't seem to find any documentation anywhere on what formats one can pass in to .ToString()
on NuGet.Versioning.SemanticVersion
. The value seems to be indexing into a list of _formatters
but there's no docs on what values are available by default, what the default behavior is, how to tweak it, etc.
e.g. this is all that's in the source code:
//
// Summary:
// Gives a normalized representation of the version. This string is unique to the
// identity of the version and does not contain metadata.
public virtual string ToNormalizedString()
{
return ToString("N", VersionFormatter.Instance);
}
//
// Summary:
// Gives a full representation of the version include metadata. This string is not
// unique to the identity of the version. Other versions that differ on metadata
// will have a different full string representation.
public virtual string ToFullString()
{
return ToString("F", VersionFormatter.Instance);
}
//
// Summary:
// Get the normalized string.
public override string ToString()
{
return ToNormalizedString();
}
//
// Summary:
// Custom string format.
public virtual string ToString(string format, IFormatProvider formatProvider)
{
string formattedString = null;
if (formatProvider == null || !TryFormatter(format, formatProvider, out formattedString))
{
formattedString = ToString();
}
return formattedString;
}
Anybody know where I can find this?
Upvotes: 1
Views: 427
Reputation: 15041
You were so close to finding the list of format characters yourself!
The first two methods you copied into your question reference a property VersionFormatter.Instance
. Looking at the VersionFormatter
class, the Format
method enumerates the list of characters it handles: https://github.com/NuGet/NuGet.Client/blob/08a7a7bd17e504d808329dcc1ffc866d9f59d040/src/NuGet.Core/NuGet.Versioning/VersionFormatter.cs#L65-L101
character | method |
---|---|
N | AppendNormalized(builder, version); |
V | AppendVersion(builder, version); |
F | AppendFull(builder, version); |
R | builder.Append(version.Release); |
M | builder.Append(version.Metadata); |
x | builder.Append(version.Major); |
y | builder.Append(version.Minor); |
z | builder.Append(version.Patch); |
r | builder.Append(version is NuGetVersion nuGetVersion && nuGetVersion.IsLegacyVersion ? nuGetVersion.Version.Revision : 0); |
Upvotes: 3