Skip to content

Commit 7250cec

Browse files
committed
Merge branch 'allow-major-precision'
2 parents 315d9c4 + 382ef84 commit 7250cec

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

src/NerdBank.GitVersioning.Tests/BuildIntegrationTests.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ public async Task GetBuildVersion_CustomAssemblyVersion()
311311
}
312312

313313
[Theory]
314+
[InlineData(VersionOptions.VersionPrecision.Major)]
314315
[InlineData(VersionOptions.VersionPrecision.Build)]
315316
[InlineData(VersionOptions.VersionPrecision.Revision)]
316317
public async Task GetBuildVersion_CustomAssemblyVersionWithPrecision(VersionOptions.VersionPrecision precision)
@@ -331,6 +332,7 @@ public async Task GetBuildVersion_CustomAssemblyVersionWithPrecision(VersionOpti
331332
}
332333

333334
[Theory]
335+
[InlineData(VersionOptions.VersionPrecision.Major)]
334336
[InlineData(VersionOptions.VersionPrecision.Build)]
335337
[InlineData(VersionOptions.VersionPrecision.Revision)]
336338
public async Task GetBuildVersion_CustomAssemblyVersionPrecision(VersionOptions.VersionPrecision precision)
@@ -750,11 +752,15 @@ public async Task AssemblyInfo_SuppressedImplicitlyByTargetExt()
750752

751753
private static Version GetExpectedAssemblyVersion(VersionOptions versionOptions, Version version)
752754
{
753-
var assemblyVersionPrecision = versionOptions.AssemblyVersion?.Precision ?? VersionOptions.VersionPrecision.Minor;
754-
int assemblyVersionBuild = assemblyVersionPrecision >= VersionOptions.VersionPrecision.Build ? version.Build : 0;
755-
int assemblyVersionRevision = assemblyVersionPrecision >= VersionOptions.VersionPrecision.Revision ? version.Revision : 0;
756-
Version assemblyVersion = (versionOptions.AssemblyVersion?.Version ?? versionOptions.Version.Version).EnsureNonNegativeComponents();
757-
assemblyVersion = new Version(assemblyVersion.Major, assemblyVersion.Minor, assemblyVersionBuild, assemblyVersionRevision);
755+
// Function should be very similar to VersionOracle.GetAssemblyVersion()
756+
var assemblyVersion = (versionOptions?.AssemblyVersion?.Version ?? versionOptions.Version.Version).EnsureNonNegativeComponents();
757+
var precision = versionOptions?.AssemblyVersion?.Precision ?? VersionOptions.DefaultVersionPrecision;
758+
759+
assemblyVersion = new System.Version(
760+
assemblyVersion.Major,
761+
precision >= VersionOptions.VersionPrecision.Minor ? assemblyVersion.Minor : 0,
762+
precision >= VersionOptions.VersionPrecision.Build ? version.Build : 0,
763+
precision >= VersionOptions.VersionPrecision.Revision ? version.Revision : 0);
758764
return assemblyVersion;
759765
}
760766

src/NerdBank.GitVersioning/AssemblyVersionOptionsConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
4545
var data = value as VersionOptions.AssemblyVersionOptions;
4646
if (data != null)
4747
{
48-
if (data.Precision == default(VersionOptions.VersionPrecision))
48+
if (data.Precision == VersionOptions.DefaultVersionPrecision)
4949
{
5050
serializer.Serialize(writer, data.Version);
5151
return;

src/NerdBank.GitVersioning/VersionOptions.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using System;
44
using System.Collections.Generic;
5+
using System.ComponentModel;
56
using System.Diagnostics;
67
using System.Reflection;
78
using Newtonsoft.Json;
@@ -13,6 +14,11 @@
1314
[DebuggerDisplay("{DebuggerDisplay,nq}")]
1415
public class VersionOptions : IEquatable<VersionOptions>
1516
{
17+
/// <summary>
18+
/// Default value for <see cref="VersionPrecision"/>.
19+
/// </summary>
20+
public const VersionPrecision DefaultVersionPrecision = VersionPrecision.Minor;
21+
1622
/// <summary>
1723
/// The JSON serializer settings to use.
1824
/// </summary>
@@ -162,7 +168,7 @@ public AssemblyVersionOptions()
162168
/// </summary>
163169
/// <param name="version">The assembly version (with major.minor components).</param>
164170
/// <param name="precision">The additional version precision to add toward matching the AssemblyFileVersion.</param>
165-
public AssemblyVersionOptions(Version version, VersionPrecision precision = default(VersionPrecision))
171+
public AssemblyVersionOptions(Version version, VersionPrecision precision = DefaultVersionPrecision)
166172
{
167173
this.Version = version;
168174
this.Precision = precision;
@@ -178,7 +184,8 @@ public AssemblyVersionOptions()
178184
/// Gets or sets the additional version precision to add toward matching the AssemblyFileVersion.
179185
/// </summary>
180186
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
181-
public VersionPrecision Precision { get; set; }
187+
[DefaultValue(DefaultVersionPrecision)]
188+
public VersionPrecision Precision { get; set; } = DefaultVersionPrecision;
182189

183190
/// <inheritdoc />
184191
public override bool Equals(object obj) => this.Equals(obj as AssemblyVersionOptions);
@@ -368,6 +375,11 @@ public override int GetHashCode()
368375
/// </summary>
369376
public enum VersionPrecision
370377
{
378+
/// <summary>
379+
/// The first integer is the last number set. The rest will be zeros.
380+
/// </summary>
381+
Major,
382+
371383
/// <summary>
372384
/// The second integer is the last number set. The rest will be zeros.
373385
/// </summary>

src/NerdBank.GitVersioning/VersionOracle.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,13 @@ private static Version GetAssemblyVersion(Version version, VersionOptions versio
282282
version = version.EnsureNonNegativeComponents();
283283

284284
var assemblyVersion = versionOptions?.AssemblyVersion?.Version ?? new System.Version(version.Major, version.Minor);
285+
var precision = versionOptions?.AssemblyVersion?.Precision ?? VersionOptions.DefaultVersionPrecision;
286+
285287
assemblyVersion = new System.Version(
286288
assemblyVersion.Major,
287-
assemblyVersion.Minor,
288-
versionOptions?.AssemblyVersion?.Precision >= VersionOptions.VersionPrecision.Build ? version.Build : 0,
289-
versionOptions?.AssemblyVersion?.Precision >= VersionOptions.VersionPrecision.Revision ? version.Revision : 0);
289+
precision >= VersionOptions.VersionPrecision.Minor ? assemblyVersion.Minor : 0,
290+
precision >= VersionOptions.VersionPrecision.Build ? version.Build : 0,
291+
precision >= VersionOptions.VersionPrecision.Revision ? version.Revision : 0);
290292
return assemblyVersion.EnsureNonNegativeComponents(4);
291293
}
292294
}

src/NerdBank.GitVersioning/version.schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"precision": {
2121
"type": "string",
2222
"description": "Identifies the last component to be explicitly set in the version.",
23-
"enum": [ "minor", "build", "revision" ],
23+
"enum": [ "major", "minor", "build", "revision" ],
2424
"default": "minor"
2525
}
2626
}

0 commit comments

Comments
 (0)