Skip to content

Commit 1d9e30c

Browse files
authored
Merge pull request #921 from onovotny/exclude-assemblyversion
Allow `assembly-versioning-scheme` to be set to `None` to skip updating the `AssemblyVersion` while still updating the `AssemblyFileVersion` and `AssemblyInformationVersion` attributes.
2 parents 9643410 + 2ffc19e commit 1d9e30c

13 files changed

+90
-6
lines changed

docs/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ The global configuration options are:
1818

1919
- **`next-version:`** Allows you to bump the next version explicitly, useful for bumping `master` or a feature with breaking changes a major increment.
2020

21-
- **`assembly-versioning-scheme:`** When updating assembly info tells GitVersion how to treat the `AssemblyVersion` attribute. Useful to lock the major when using Strong Naming.
21+
- **`assembly-versioning-scheme:`** When updating assembly info tells GitVersion how to treat the `AssemblyVersion` attribute. Useful to lock the major when using Strong Naming. Note: you can use `None` to skip updating the `AssemblyVersion` while still updating the `AssemblyFileVersion` and `AssemblyInformationVersion` attributes.
2222

2323
- **`assembly-informational-format:`** Set this to any of the available [variables](/more-info/variables) to change the value of the `AssemblyInformationalVersion` attribute. Default set to `{InformationalVersion}`. It also supports string interpolation (`{MajorMinorPatch}+{Branch}`)
2424

src/GitVersionCore/AssemblyVersioningScheme.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public enum AssemblyVersioningScheme
55
MajorMinorPatchTag,
66
MajorMinorPatch,
77
MajorMinor,
8-
Major
8+
Major,
9+
None
910
}
1011
}

src/GitVersionCore/AssemblyVersionsGenerator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ public static string GetAssemblyVersion(
1818
return string.Format("{0}.{1}.{2}.0", sv.Major, sv.Minor, sv.Patch);
1919
case AssemblyVersioningScheme.MajorMinorPatchTag:
2020
return string.Format("{0}.{1}.{2}.{3}", sv.Major, sv.Minor, sv.Patch, sv.PreReleaseTag.Number ?? 0);
21+
case AssemblyVersioningScheme.None:
22+
return null;
2123
default:
2224
throw new ArgumentException(string.Format("Unexpected value ({0}).", scheme), "scheme");
2325
}

src/GitVersionCore/Configuration/Init/SetConfig/AssemblyVersioningSchemeSetting.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
3333
config.AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatchTag;
3434
steps.Enqueue(new EditConfigStep(Console, FileSystem));
3535
return StepResult.Ok();
36+
case "5":
37+
config.AssemblyVersioningScheme = AssemblyVersioningScheme.None;
38+
steps.Enqueue(new EditConfigStep(Console, FileSystem));
39+
return StepResult.Ok();
3640
}
3741

3842
return StepResult.InvalidResponseSelected();
@@ -46,7 +50,9 @@ protected override string GetPrompt(Config config, string workingDirectory)
4650
1) Major.0.0.0
4751
2) Major.Minor.0.0
4852
3) Major.Minor.Patch.0 (default)
49-
4) Major.Minor.Patch.TagCount (Allows different pre-release tags to cause assembly version to change)";
53+
4) Major.Minor.Patch.TagCount (Allows different pre-release tags to cause assembly version to change)
54+
5) None (skip's updating AssemblyVersion)";
55+
5056
}
5157

5258
protected override string DefaultResult
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[assembly: AssemblyFileVersion("2.3.1.0")]
2+
[assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[assembly: AssemblyFileVersion("2.3.1.0")]
2+
[assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[<assembly: AssemblyFileVersion("2.3.1.0")>]
2+
[<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[<assembly: AssemblyFileVersion("2.3.1.0")>]
2+
[<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<Assembly: AssemblyFileVersion("2.3.1.0")>
2+
<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<Assembly: AssemblyFileVersion("2.3.1.0")>
2+
<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>

src/GitVersionExe.Tests/AssemblyInfoFileUpdateTests.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,36 @@ public void ShouldReplaceAssemblyVersion(string fileExtension, string assemblyFi
206206
});
207207
}
208208

209+
210+
[TestCase("cs", "[assembly: AssemblyFileVersion(\"1.0.0.0\")]")]
211+
[TestCase("fs", "[<assembly: AssemblyFileVersion(\"1.0.0.0\")>]")]
212+
[TestCase("vb", "<Assembly: AssemblyFileVersion(\"1.0.0.0\")>")]
213+
[Category("NoMono")]
214+
[Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")]
215+
public void ShouldNotReplaceAssemblyVersionWhenVersionSchemeIsNone(string fileExtension, string assemblyFileContent)
216+
{
217+
var workingDir = Path.GetTempPath();
218+
var fileName = Path.Combine(workingDir, "AssemblyInfo." + fileExtension);
219+
220+
VerifyAssemblyInfoFile(assemblyFileContent, fileName, AssemblyVersioningScheme.None, verify: (fileSystem, variables) =>
221+
{
222+
var args = new Arguments
223+
{
224+
UpdateAssemblyInfo = true,
225+
UpdateAssemblyInfoFileName = new HashSet<string>
226+
{
227+
"AssemblyInfo." + fileExtension
228+
}
229+
};
230+
231+
using (new AssemblyInfoFileUpdate(args, workingDir, variables, fileSystem))
232+
{
233+
assemblyFileContent = fileSystem.ReadAllText(fileName);
234+
assemblyFileContent.ShouldMatchApproved(c => c.SubFolder(Path.Combine("Approved", fileExtension)));
235+
}
236+
});
237+
}
238+
209239
[TestCase("cs", "[assembly: AssemblyVersion(\"1.0.0.0\")]\r\n[assembly: AssemblyInformationalVersion(\"1.0.0.0\")]\r\n[assembly: AssemblyFileVersion(\"1.0.0.0\")]")]
210240
[TestCase("fs", "[<assembly: AssemblyVersion(\"1.0.0.0\")>]\r\n[<assembly: AssemblyInformationalVersion(\"1.0.0.0\")>]\r\n[<assembly: AssemblyFileVersion(\"1.0.0.0\")>]")]
211241
[TestCase("vb", "<Assembly: AssemblyVersion(\"1.0.0.0\")>\r\n<Assembly: AssemblyInformationalVersion(\"1.0.0.0\")>\r\n<Assembly: AssemblyFileVersion(\"1.0.0.0\")>")]
@@ -414,6 +444,36 @@ public void ShouldAddAssemblyInformationalVersionWhenUpdatingAssemblyVersionFile
414444
});
415445
}
416446

447+
448+
[TestCase("cs", "[assembly: AssemblyFileVersion(\"1.0.0.0\")]")]
449+
[TestCase("fs", "[<assembly: AssemblyFileVersion(\"1.0.0.0\")>]")]
450+
[TestCase("vb", "<Assembly: AssemblyFileVersion(\"1.0.0.0\")>")]
451+
[Category("NoMono")]
452+
[Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")]
453+
public void ShouldNotAddAssemblyInformationalVersionWhenUpdatingAssemblyVersionFileWhenVersionSchemeIsNone(string fileExtension, string assemblyFileContent)
454+
{
455+
var workingDir = Path.GetTempPath();
456+
var fileName = Path.Combine(workingDir, "AssemblyInfo." + fileExtension);
457+
458+
VerifyAssemblyInfoFile(assemblyFileContent, fileName, AssemblyVersioningScheme.None, verify: (fileSystem, variables) =>
459+
{
460+
var args = new Arguments
461+
{
462+
UpdateAssemblyInfo = true,
463+
UpdateAssemblyInfoFileName = new HashSet<string>
464+
{
465+
"AssemblyInfo." + fileExtension
466+
}
467+
};
468+
469+
using (new AssemblyInfoFileUpdate(args, workingDir, variables, fileSystem))
470+
{
471+
assemblyFileContent = fileSystem.ReadAllText(fileName);
472+
assemblyFileContent.ShouldMatchApproved(c => c.SubFolder(Path.Combine("Approved", fileExtension)));
473+
}
474+
});
475+
}
476+
417477
private static void VerifyAssemblyInfoFile(
418478
string assemblyFileContent,
419479
string fileName,

src/GitVersionExe/AssemblyInfoFileUpdate.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, VersionVa
2626

2727
var assemblyVersion = variables.AssemblySemVer;
2828
var assemblyVersionRegex = new Regex(@"AssemblyVersion\s*\(\s*""[^""]*""\s*\)");
29-
var assemblyVersionString = string.Format("AssemblyVersion(\"{0}\")", assemblyVersion);
29+
var assemblyVersionString = !string.IsNullOrWhiteSpace(assemblyVersion) ? string.Format("AssemblyVersion(\"{0}\")", assemblyVersion) : null;
3030
var assemblyInfoVersion = variables.InformationalVersion;
3131
var assemblyInfoVersionRegex = new Regex(@"AssemblyInformationalVersion\s*\(\s*""[^""]*""\s*\)");
3232
var assemblyInfoVersionString = string.Format("AssemblyInformationalVersion(\"{0}\")", assemblyInfoVersion);
@@ -48,7 +48,10 @@ public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, VersionVa
4848
cleanupBackupTasks.Add(() => fileSystem.Delete(backupAssemblyInfo));
4949

5050
var fileContents = fileSystem.ReadAllText(assemblyInfoFile.FullName);
51-
fileContents = ReplaceOrAppend(assemblyVersionRegex, fileContents, assemblyVersionString, assemblyInfoFile.Extension);
51+
if (!string.IsNullOrWhiteSpace(assemblyVersion))
52+
{
53+
fileContents = ReplaceOrAppend(assemblyVersionRegex, fileContents, assemblyVersionString, assemblyInfoFile.Extension);
54+
}
5255
fileContents = ReplaceOrAppend(assemblyInfoVersionRegex, fileContents, assemblyInfoVersionString, assemblyInfoFile.Extension);
5356
fileContents = ReplaceOrAppend(assemblyFileVersionRegex, fileContents, assemblyFileVersionString, assemblyInfoFile.Extension);
5457

src/GitVersionExe/HelpWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ path The directory containing .git. If not defined current directory
3535
Specify name of AssemblyInfo file. Can also /updateAssemblyInfo GlobalAssemblyInfo.cs as a shorthand
3636
/ensureassemblyinfo
3737
If the assembly info file specified with /updateassemblyinfo or /updateassemblyinfofilename is not found,
38-
it be created with these attributes: AssemblyFileVersion, FileVersion and AssemblyInformationalVersion
38+
it be created with these attributes: AssemblyFileVersion, AssemblyVersion and AssemblyInformationalVersion
3939
---
4040
Supports writing version info for: C#, F#, VB
4141
# Remote repository args

0 commit comments

Comments
 (0)