diff --git a/docs/configuration.md b/docs/configuration.md index 7d1bf22672..bea563f6e1 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -18,7 +18,7 @@ The global configuration options are: - **`next-version:`** Allows you to bump the next version explicitly, useful for bumping `master` or a feature with breaking changes a major increment. - - **`assembly-versioning-scheme:`** When updating assembly info tells GitVersion how to treat the `AssemblyVersion` attribute. Useful to lock the major when using Strong Naming. + - **`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. - **`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}`) diff --git a/src/GitVersionCore/AssemblyVersioningScheme.cs b/src/GitVersionCore/AssemblyVersioningScheme.cs index 87cc4259a7..9a77fa380d 100644 --- a/src/GitVersionCore/AssemblyVersioningScheme.cs +++ b/src/GitVersionCore/AssemblyVersioningScheme.cs @@ -5,6 +5,7 @@ public enum AssemblyVersioningScheme MajorMinorPatchTag, MajorMinorPatch, MajorMinor, - Major + Major, + None } } \ No newline at end of file diff --git a/src/GitVersionCore/AssemblyVersionsGenerator.cs b/src/GitVersionCore/AssemblyVersionsGenerator.cs index 0010013d57..7fbf5778a6 100644 --- a/src/GitVersionCore/AssemblyVersionsGenerator.cs +++ b/src/GitVersionCore/AssemblyVersionsGenerator.cs @@ -18,6 +18,8 @@ public static string GetAssemblyVersion( return string.Format("{0}.{1}.{2}.0", sv.Major, sv.Minor, sv.Patch); case AssemblyVersioningScheme.MajorMinorPatchTag: return string.Format("{0}.{1}.{2}.{3}", sv.Major, sv.Minor, sv.Patch, sv.PreReleaseTag.Number ?? 0); + case AssemblyVersioningScheme.None: + return null; default: throw new ArgumentException(string.Format("Unexpected value ({0}).", scheme), "scheme"); } diff --git a/src/GitVersionCore/Configuration/Init/SetConfig/AssemblyVersioningSchemeSetting.cs b/src/GitVersionCore/Configuration/Init/SetConfig/AssemblyVersioningSchemeSetting.cs index 9f426a4f43..ebabdd1bec 100644 --- a/src/GitVersionCore/Configuration/Init/SetConfig/AssemblyVersioningSchemeSetting.cs +++ b/src/GitVersionCore/Configuration/Init/SetConfig/AssemblyVersioningSchemeSetting.cs @@ -33,6 +33,10 @@ protected override StepResult HandleResult(string result, Queue] +[] \ No newline at end of file diff --git a/src/GitVersionExe.Tests/Approved/fs/AssemblyInfoFileUpdateTests.ShouldNotReplaceAssemblyVersionWhenVersionSchemeIsNone.approved.txt b/src/GitVersionExe.Tests/Approved/fs/AssemblyInfoFileUpdateTests.ShouldNotReplaceAssemblyVersionWhenVersionSchemeIsNone.approved.txt new file mode 100644 index 0000000000..91c2987c43 --- /dev/null +++ b/src/GitVersionExe.Tests/Approved/fs/AssemblyInfoFileUpdateTests.ShouldNotReplaceAssemblyVersionWhenVersionSchemeIsNone.approved.txt @@ -0,0 +1,2 @@ +[] +[] \ No newline at end of file diff --git a/src/GitVersionExe.Tests/Approved/vb/AssemblyInfoFileUpdateTests.ShouldNotAddAssemblyInformationalVersionWhenUpdatingAssemblyVersionFileWhenVersionSchemeIsNone.approved.txt b/src/GitVersionExe.Tests/Approved/vb/AssemblyInfoFileUpdateTests.ShouldNotAddAssemblyInformationalVersionWhenUpdatingAssemblyVersionFileWhenVersionSchemeIsNone.approved.txt new file mode 100644 index 0000000000..c66faf90a7 --- /dev/null +++ b/src/GitVersionExe.Tests/Approved/vb/AssemblyInfoFileUpdateTests.ShouldNotAddAssemblyInformationalVersionWhenUpdatingAssemblyVersionFileWhenVersionSchemeIsNone.approved.txt @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/src/GitVersionExe.Tests/Approved/vb/AssemblyInfoFileUpdateTests.ShouldNotReplaceAssemblyVersionWhenVersionSchemeIsNone.approved.txt b/src/GitVersionExe.Tests/Approved/vb/AssemblyInfoFileUpdateTests.ShouldNotReplaceAssemblyVersionWhenVersionSchemeIsNone.approved.txt new file mode 100644 index 0000000000..c66faf90a7 --- /dev/null +++ b/src/GitVersionExe.Tests/Approved/vb/AssemblyInfoFileUpdateTests.ShouldNotReplaceAssemblyVersionWhenVersionSchemeIsNone.approved.txt @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/src/GitVersionExe.Tests/AssemblyInfoFileUpdateTests.cs b/src/GitVersionExe.Tests/AssemblyInfoFileUpdateTests.cs index d9e6bc2340..0a0b2e6ad6 100644 --- a/src/GitVersionExe.Tests/AssemblyInfoFileUpdateTests.cs +++ b/src/GitVersionExe.Tests/AssemblyInfoFileUpdateTests.cs @@ -206,6 +206,36 @@ public void ShouldReplaceAssemblyVersion(string fileExtension, string assemblyFi }); } + + [TestCase("cs", "[assembly: AssemblyFileVersion(\"1.0.0.0\")]")] + [TestCase("fs", "[]")] + [TestCase("vb", "")] + [Category("NoMono")] + [Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] + public void ShouldNotReplaceAssemblyVersionWhenVersionSchemeIsNone(string fileExtension, string assemblyFileContent) + { + var workingDir = Path.GetTempPath(); + var fileName = Path.Combine(workingDir, "AssemblyInfo." + fileExtension); + + VerifyAssemblyInfoFile(assemblyFileContent, fileName, AssemblyVersioningScheme.None, verify: (fileSystem, variables) => + { + var args = new Arguments + { + UpdateAssemblyInfo = true, + UpdateAssemblyInfoFileName = new HashSet + { + "AssemblyInfo." + fileExtension + } + }; + + using (new AssemblyInfoFileUpdate(args, workingDir, variables, fileSystem)) + { + assemblyFileContent = fileSystem.ReadAllText(fileName); + assemblyFileContent.ShouldMatchApproved(c => c.SubFolder(Path.Combine("Approved", fileExtension))); + } + }); + } + [TestCase("cs", "[assembly: AssemblyVersion(\"1.0.0.0\")]\r\n[assembly: AssemblyInformationalVersion(\"1.0.0.0\")]\r\n[assembly: AssemblyFileVersion(\"1.0.0.0\")]")] [TestCase("fs", "[]\r\n[]\r\n[]")] [TestCase("vb", "\r\n\r\n")] @@ -414,6 +444,36 @@ public void ShouldAddAssemblyInformationalVersionWhenUpdatingAssemblyVersionFile }); } + + [TestCase("cs", "[assembly: AssemblyFileVersion(\"1.0.0.0\")]")] + [TestCase("fs", "[]")] + [TestCase("vb", "")] + [Category("NoMono")] + [Description("Won't run on Mono due to source information not being available for ShouldMatchApproved.")] + public void ShouldNotAddAssemblyInformationalVersionWhenUpdatingAssemblyVersionFileWhenVersionSchemeIsNone(string fileExtension, string assemblyFileContent) + { + var workingDir = Path.GetTempPath(); + var fileName = Path.Combine(workingDir, "AssemblyInfo." + fileExtension); + + VerifyAssemblyInfoFile(assemblyFileContent, fileName, AssemblyVersioningScheme.None, verify: (fileSystem, variables) => + { + var args = new Arguments + { + UpdateAssemblyInfo = true, + UpdateAssemblyInfoFileName = new HashSet + { + "AssemblyInfo." + fileExtension + } + }; + + using (new AssemblyInfoFileUpdate(args, workingDir, variables, fileSystem)) + { + assemblyFileContent = fileSystem.ReadAllText(fileName); + assemblyFileContent.ShouldMatchApproved(c => c.SubFolder(Path.Combine("Approved", fileExtension))); + } + }); + } + private static void VerifyAssemblyInfoFile( string assemblyFileContent, string fileName, diff --git a/src/GitVersionExe/AssemblyInfoFileUpdate.cs b/src/GitVersionExe/AssemblyInfoFileUpdate.cs index 4646ad7dda..a8de25f99d 100644 --- a/src/GitVersionExe/AssemblyInfoFileUpdate.cs +++ b/src/GitVersionExe/AssemblyInfoFileUpdate.cs @@ -26,7 +26,7 @@ public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, VersionVa var assemblyVersion = variables.AssemblySemVer; var assemblyVersionRegex = new Regex(@"AssemblyVersion\s*\(\s*""[^""]*""\s*\)"); - var assemblyVersionString = string.Format("AssemblyVersion(\"{0}\")", assemblyVersion); + var assemblyVersionString = !string.IsNullOrWhiteSpace(assemblyVersion) ? string.Format("AssemblyVersion(\"{0}\")", assemblyVersion) : null; var assemblyInfoVersion = variables.InformationalVersion; var assemblyInfoVersionRegex = new Regex(@"AssemblyInformationalVersion\s*\(\s*""[^""]*""\s*\)"); var assemblyInfoVersionString = string.Format("AssemblyInformationalVersion(\"{0}\")", assemblyInfoVersion); @@ -48,7 +48,10 @@ public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, VersionVa cleanupBackupTasks.Add(() => fileSystem.Delete(backupAssemblyInfo)); var fileContents = fileSystem.ReadAllText(assemblyInfoFile.FullName); - fileContents = ReplaceOrAppend(assemblyVersionRegex, fileContents, assemblyVersionString, assemblyInfoFile.Extension); + if (!string.IsNullOrWhiteSpace(assemblyVersion)) + { + fileContents = ReplaceOrAppend(assemblyVersionRegex, fileContents, assemblyVersionString, assemblyInfoFile.Extension); + } fileContents = ReplaceOrAppend(assemblyInfoVersionRegex, fileContents, assemblyInfoVersionString, assemblyInfoFile.Extension); fileContents = ReplaceOrAppend(assemblyFileVersionRegex, fileContents, assemblyFileVersionString, assemblyInfoFile.Extension); diff --git a/src/GitVersionExe/HelpWriter.cs b/src/GitVersionExe/HelpWriter.cs index 0f54351b57..b1041f04ee 100644 --- a/src/GitVersionExe/HelpWriter.cs +++ b/src/GitVersionExe/HelpWriter.cs @@ -35,7 +35,7 @@ path The directory containing .git. If not defined current directory Specify name of AssemblyInfo file. Can also /updateAssemblyInfo GlobalAssemblyInfo.cs as a shorthand /ensureassemblyinfo If the assembly info file specified with /updateassemblyinfo or /updateassemblyinfofilename is not found, - it be created with these attributes: AssemblyFileVersion, FileVersion and AssemblyInformationalVersion + it be created with these attributes: AssemblyFileVersion, AssemblyVersion and AssemblyInformationalVersion --- Supports writing version info for: C#, F#, VB # Remote repository args