diff --git a/src/NerdBank.GitVersioning/VersionOracle.cs b/src/NerdBank.GitVersioning/VersionOracle.cs index 297da93c..8f43f8c5 100644 --- a/src/NerdBank.GitVersioning/VersionOracle.cs +++ b/src/NerdBank.GitVersioning/VersionOracle.cs @@ -170,6 +170,7 @@ public IEnumerable BuildMetadataWithCommitId /// /// Gets the version options used to initialize this instance. /// + [Ignore] public VersionOptions? VersionOptions { get; } /// @@ -296,17 +297,27 @@ public IEnumerable BuildMetadataWithCommitId { var variables = new Dictionary(StringComparer.OrdinalIgnoreCase); - PropertyInfo[]? properties = this.GetType().GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance); - foreach (PropertyInfo? property in properties) + PropertyInfo[] properties = this.GetType().GetTypeInfo().GetProperties(BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance); + foreach (PropertyInfo property in properties) { - if (property.GetCustomAttribute() is null) + if (property.GetCustomAttribute() is not null) + { + continue; + } + + object? propertyValue = property.GetValue(this); + if (propertyValue is null) { - object? value = property.GetValue(this); - if (value is object) - { - variables.Add($"NBGV_{property.Name}", value.ToString() ?? string.Empty); - } + continue; } + + string value = propertyValue switch + { + DateTimeOffset dateTimeOffset => dateTimeOffset.ToString("o", CultureInfo.InvariantCulture), + _ => Convert.ToString(propertyValue, CultureInfo.InvariantCulture) ?? string.Empty, + }; + + variables.Add($"NBGV_{property.Name}", value); } return variables;