Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)

Expand Down
3 changes: 2 additions & 1 deletion src/GitVersionCore/AssemblyVersioningScheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public enum AssemblyVersioningScheme
MajorMinorPatchTag,
MajorMinorPatch,
MajorMinor,
Major
Major,
None
}
}
2 changes: 2 additions & 0 deletions src/GitVersionCore/AssemblyVersionsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ protected override StepResult HandleResult(string result, Queue<ConfigInitWizard
config.AssemblyVersioningScheme = AssemblyVersioningScheme.MajorMinorPatchTag;
steps.Enqueue(new EditConfigStep(Console, FileSystem));
return StepResult.Ok();
case "5":
config.AssemblyVersioningScheme = AssemblyVersioningScheme.None;
steps.Enqueue(new EditConfigStep(Console, FileSystem));
return StepResult.Ok();
}

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

}

protected override string DefaultResult
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[assembly: AssemblyFileVersion("2.3.1.0")]
[assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[assembly: AssemblyFileVersion("2.3.1.0")]
[assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[<assembly: AssemblyFileVersion("2.3.1.0")>]
[<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[<assembly: AssemblyFileVersion("2.3.1.0")>]
[<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<Assembly: AssemblyFileVersion("2.3.1.0")>
<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<Assembly: AssemblyFileVersion("2.3.1.0")>
<assembly: AssemblyInformationalVersion("2.3.1+3.Branch.foo.Sha.hash")>
60 changes: 60 additions & 0 deletions src/GitVersionExe.Tests/AssemblyInfoFileUpdateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,36 @@ public void ShouldReplaceAssemblyVersion(string fileExtension, string assemblyFi
});
}


[TestCase("cs", "[assembly: AssemblyFileVersion(\"1.0.0.0\")]")]
[TestCase("fs", "[<assembly: AssemblyFileVersion(\"1.0.0.0\")>]")]
[TestCase("vb", "<Assembly: AssemblyFileVersion(\"1.0.0.0\")>")]
[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<string>
{
"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", "[<assembly: AssemblyVersion(\"1.0.0.0\")>]\r\n[<assembly: AssemblyInformationalVersion(\"1.0.0.0\")>]\r\n[<assembly: AssemblyFileVersion(\"1.0.0.0\")>]")]
[TestCase("vb", "<Assembly: AssemblyVersion(\"1.0.0.0\")>\r\n<Assembly: AssemblyInformationalVersion(\"1.0.0.0\")>\r\n<Assembly: AssemblyFileVersion(\"1.0.0.0\")>")]
Expand Down Expand Up @@ -414,6 +444,36 @@ public void ShouldAddAssemblyInformationalVersionWhenUpdatingAssemblyVersionFile
});
}


[TestCase("cs", "[assembly: AssemblyFileVersion(\"1.0.0.0\")]")]
[TestCase("fs", "[<assembly: AssemblyFileVersion(\"1.0.0.0\")>]")]
[TestCase("vb", "<Assembly: AssemblyFileVersion(\"1.0.0.0\")>")]
[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<string>
{
"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,
Expand Down
7 changes: 5 additions & 2 deletions src/GitVersionExe/AssemblyInfoFileUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/GitVersionExe/HelpWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down