From 13ad05dc83eda31ab6478af9aedcb127336edddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Tue, 21 Jul 2015 16:23:01 +0200 Subject: [PATCH 1/9] R# cleanup --- src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs b/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs index f6e5919ea9..4e4ce74958 100644 --- a/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs +++ b/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Text; + using GitVersion; public class AssemblyInfoBuilder @@ -45,6 +46,7 @@ static class GitVersionInformation return assemblyInfo; } + string GenerateVariableMembers(IEnumerable> vars) { var members = new StringBuilder(); From f7db56ed4035567f2620bf867d5b84fd92367b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Tue, 21 Jul 2015 16:27:32 +0200 Subject: [PATCH 2/9] Remove extranous whitespace from the generated AssemblyInfo file --- ...s.VerifyAssemblyVersion_Major.approved.txt | 4 +--- ...ifyAssemblyVersion_MajorMinor.approved.txt | 4 +--- ...semblyVersion_MajorMinorPatch.approved.txt | 4 +--- ...blyVersion_MajorMinorPatchTag.approved.txt | 4 +--- ...uilderTests.VerifyCreatedCode.approved.txt | 4 +--- .../AssemblyInfoBuilder.cs | 22 +++++++++++++------ 6 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt index c1047738fc..47b521c700 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt @@ -1,5 +1,4 @@ - -using System; +using System; using System.Reflection; [assembly: AssemblyVersion("2.0.0.0")] @@ -42,6 +41,5 @@ namespace Fake public static string NuGetVersionV2 = "2.3.4-beta0005"; public static string NuGetVersion = "2.3.4-beta0005"; public static string CommitDate = "2014-03-06"; - } } diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt index 4bd9fc75a1..487522d1c8 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt @@ -1,5 +1,4 @@ - -using System; +using System; using System.Reflection; [assembly: AssemblyVersion("2.3.0.0")] @@ -42,6 +41,5 @@ namespace Fake public static string NuGetVersionV2 = "2.3.4-beta0005"; public static string NuGetVersion = "2.3.4-beta0005"; public static string CommitDate = "2014-03-06"; - } } diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt index cbd123be6d..4fad4c7042 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt @@ -1,5 +1,4 @@ - -using System; +using System; using System.Reflection; [assembly: AssemblyVersion("2.3.4.0")] @@ -42,6 +41,5 @@ namespace Fake public static string NuGetVersionV2 = "2.3.4-beta0005"; public static string NuGetVersion = "2.3.4-beta0005"; public static string CommitDate = "2014-03-06"; - } } diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt index cf4392da2d..709ee187f2 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt @@ -1,5 +1,4 @@ - -using System; +using System; using System.Reflection; [assembly: AssemblyVersion("2.3.4.5")] @@ -42,6 +41,5 @@ namespace Fake public static string NuGetVersionV2 = "2.3.4-beta0005"; public static string NuGetVersion = "2.3.4-beta0005"; public static string CommitDate = "2014-03-06"; - } } diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt index f0c6488df1..93953be6f9 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt @@ -1,5 +1,4 @@ - -using System; +using System; using System.Reflection; [assembly: AssemblyVersion("1.2.3.0")] @@ -42,6 +41,5 @@ namespace Fake public static string NuGetVersionV2 = "1.2.3-unstable0004"; public static string NuGetVersion = "1.2.3-unstable0004"; public static string CommitDate = "2014-03-06"; - } } diff --git a/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs b/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs index 4e4ce74958..59407657be 100644 --- a/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs +++ b/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Linq; using System.Text; using GitVersion; @@ -7,8 +8,10 @@ public class AssemblyInfoBuilder { public string GetAssemblyInfoText(VersionVariables vars, string assemblyName) { - var assemblyInfo = string.Format(@" -using System; + var v = vars.ToArray(); + + var assemblyInfo = string.Format( +@"using System; using System.Reflection; [assembly: AssemblyVersion(""{0}"")] @@ -40,19 +43,24 @@ static class GitVersionInformation vars.MajorMinorPatch + ".0", vars.InformationalVersion, vars.CommitDate, - GenerateVariableMembers(vars), + GenerateVariableMembers(v), assemblyName); return assemblyInfo; } - - string GenerateVariableMembers(IEnumerable> vars) + static string GenerateVariableMembers(IList> vars) { var members = new StringBuilder(); - foreach (var variable in vars) + for (var i = 0; i < vars.Count; i++) { - members.AppendLine(string.Format(" public static string {0} = \"{1}\";", variable.Key, variable.Value)); + var variable = vars[i]; + members.AppendFormat(" public static string {0} = \"{1}\";", variable.Key, variable.Value); + + if (i < vars.Count - 1) + { + members.AppendLine(); + } } return members.ToString(); From aaa8908ed343a3c86d7a6b5534c8ef92d78f6d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Tue, 21 Jul 2015 16:38:44 +0200 Subject: [PATCH 3/9] Add GitVersionInformationAttribute to generated assembly info files to make reflection of the contained version information easier. --- ...s.VerifyAssemblyVersion_Major.approved.txt | 25 ++++++++++++++ ...ifyAssemblyVersion_MajorMinor.approved.txt | 25 ++++++++++++++ ...semblyVersion_MajorMinorPatch.approved.txt | 25 ++++++++++++++ ...blyVersion_MajorMinorPatchTag.approved.txt | 25 ++++++++++++++ ...uilderTests.VerifyCreatedCode.approved.txt | 25 ++++++++++++++ .../AssemblyInfoBuilder.cs | 34 ++++++++++++++++--- 6 files changed, 155 insertions(+), 4 deletions(-) diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt index 47b521c700..438b8c0d6e 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt @@ -5,6 +5,7 @@ using System.Reflection; [assembly: AssemblyFileVersion("2.3.4.0")] [assembly: AssemblyInformationalVersion("2.3.4-beta.5+6.Branch.master.Sha.commitSha")] [assembly: Fake.ReleaseDate("2014-03-06")] +[assembly: Fake.GitVersionInformation()] namespace Fake { @@ -42,4 +43,28 @@ namespace Fake public static string NuGetVersion = "2.3.4-beta0005"; public static string CommitDate = "2014-03-06"; } + + [System.Runtime.CompilerServices.CompilerGenerated] + sealed class GitVersionInformationAttribute : System.Attribute + { + public string Major { get { return "2"; } } + public string Minor { get { return "3"; } } + public string Patch { get { return "4"; } } + public string PreReleaseTag { get { return "beta.5"; } } + public string PreReleaseTagWithDash { get { return "-beta.5"; } } + public string BuildMetaData { get { return "6"; } } + public string FullBuildMetaData { get { return "6.Branch.master.Sha.commitSha"; } } + public string MajorMinorPatch { get { return "2.3.4"; } } + public string SemVer { get { return "2.3.4-beta.5"; } } + public string LegacySemVer { get { return "2.3.4-beta5"; } } + public string LegacySemVerPadded { get { return "2.3.4-beta0005"; } } + public string AssemblySemVer { get { return "2.0.0.0"; } } + public string FullSemVer { get { return "2.3.4-beta.5+6"; } } + public string InformationalVersion { get { return "2.3.4-beta.5+6.Branch.master.Sha.commitSha"; } } + public string BranchName { get { return "master"; } } + public string Sha { get { return "commitSha"; } } + public string NuGetVersionV2 { get { return "2.3.4-beta0005"; } } + public string NuGetVersion { get { return "2.3.4-beta0005"; } } + public string CommitDate { get { return "2014-03-06"; } } + } } diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt index 487522d1c8..e6ab7a1a84 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt @@ -5,6 +5,7 @@ using System.Reflection; [assembly: AssemblyFileVersion("2.3.4.0")] [assembly: AssemblyInformationalVersion("2.3.4-beta.5+6.Branch.master.Sha.commitSha")] [assembly: Fake.ReleaseDate("2014-03-06")] +[assembly: Fake.GitVersionInformation()] namespace Fake { @@ -42,4 +43,28 @@ namespace Fake public static string NuGetVersion = "2.3.4-beta0005"; public static string CommitDate = "2014-03-06"; } + + [System.Runtime.CompilerServices.CompilerGenerated] + sealed class GitVersionInformationAttribute : System.Attribute + { + public string Major { get { return "2"; } } + public string Minor { get { return "3"; } } + public string Patch { get { return "4"; } } + public string PreReleaseTag { get { return "beta.5"; } } + public string PreReleaseTagWithDash { get { return "-beta.5"; } } + public string BuildMetaData { get { return "6"; } } + public string FullBuildMetaData { get { return "6.Branch.master.Sha.commitSha"; } } + public string MajorMinorPatch { get { return "2.3.4"; } } + public string SemVer { get { return "2.3.4-beta.5"; } } + public string LegacySemVer { get { return "2.3.4-beta5"; } } + public string LegacySemVerPadded { get { return "2.3.4-beta0005"; } } + public string AssemblySemVer { get { return "2.3.0.0"; } } + public string FullSemVer { get { return "2.3.4-beta.5+6"; } } + public string InformationalVersion { get { return "2.3.4-beta.5+6.Branch.master.Sha.commitSha"; } } + public string BranchName { get { return "master"; } } + public string Sha { get { return "commitSha"; } } + public string NuGetVersionV2 { get { return "2.3.4-beta0005"; } } + public string NuGetVersion { get { return "2.3.4-beta0005"; } } + public string CommitDate { get { return "2014-03-06"; } } + } } diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt index 4fad4c7042..d567a1ab52 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt @@ -5,6 +5,7 @@ using System.Reflection; [assembly: AssemblyFileVersion("2.3.4.0")] [assembly: AssemblyInformationalVersion("2.3.4-beta.5+6.Branch.master.Sha.commitSha")] [assembly: Fake.ReleaseDate("2014-03-06")] +[assembly: Fake.GitVersionInformation()] namespace Fake { @@ -42,4 +43,28 @@ namespace Fake public static string NuGetVersion = "2.3.4-beta0005"; public static string CommitDate = "2014-03-06"; } + + [System.Runtime.CompilerServices.CompilerGenerated] + sealed class GitVersionInformationAttribute : System.Attribute + { + public string Major { get { return "2"; } } + public string Minor { get { return "3"; } } + public string Patch { get { return "4"; } } + public string PreReleaseTag { get { return "beta.5"; } } + public string PreReleaseTagWithDash { get { return "-beta.5"; } } + public string BuildMetaData { get { return "6"; } } + public string FullBuildMetaData { get { return "6.Branch.master.Sha.commitSha"; } } + public string MajorMinorPatch { get { return "2.3.4"; } } + public string SemVer { get { return "2.3.4-beta.5"; } } + public string LegacySemVer { get { return "2.3.4-beta5"; } } + public string LegacySemVerPadded { get { return "2.3.4-beta0005"; } } + public string AssemblySemVer { get { return "2.3.4.0"; } } + public string FullSemVer { get { return "2.3.4-beta.5+6"; } } + public string InformationalVersion { get { return "2.3.4-beta.5+6.Branch.master.Sha.commitSha"; } } + public string BranchName { get { return "master"; } } + public string Sha { get { return "commitSha"; } } + public string NuGetVersionV2 { get { return "2.3.4-beta0005"; } } + public string NuGetVersion { get { return "2.3.4-beta0005"; } } + public string CommitDate { get { return "2014-03-06"; } } + } } diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt index 709ee187f2..c5a67c035f 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt @@ -5,6 +5,7 @@ using System.Reflection; [assembly: AssemblyFileVersion("2.3.4.0")] [assembly: AssemblyInformationalVersion("2.3.4-beta.5+6.Branch.master.Sha.commitSha")] [assembly: Fake.ReleaseDate("2014-03-06")] +[assembly: Fake.GitVersionInformation()] namespace Fake { @@ -42,4 +43,28 @@ namespace Fake public static string NuGetVersion = "2.3.4-beta0005"; public static string CommitDate = "2014-03-06"; } + + [System.Runtime.CompilerServices.CompilerGenerated] + sealed class GitVersionInformationAttribute : System.Attribute + { + public string Major { get { return "2"; } } + public string Minor { get { return "3"; } } + public string Patch { get { return "4"; } } + public string PreReleaseTag { get { return "beta.5"; } } + public string PreReleaseTagWithDash { get { return "-beta.5"; } } + public string BuildMetaData { get { return "6"; } } + public string FullBuildMetaData { get { return "6.Branch.master.Sha.commitSha"; } } + public string MajorMinorPatch { get { return "2.3.4"; } } + public string SemVer { get { return "2.3.4-beta.5"; } } + public string LegacySemVer { get { return "2.3.4-beta5"; } } + public string LegacySemVerPadded { get { return "2.3.4-beta0005"; } } + public string AssemblySemVer { get { return "2.3.4.5"; } } + public string FullSemVer { get { return "2.3.4-beta.5+6"; } } + public string InformationalVersion { get { return "2.3.4-beta.5+6.Branch.master.Sha.commitSha"; } } + public string BranchName { get { return "master"; } } + public string Sha { get { return "commitSha"; } } + public string NuGetVersionV2 { get { return "2.3.4-beta0005"; } } + public string NuGetVersion { get { return "2.3.4-beta0005"; } } + public string CommitDate { get { return "2014-03-06"; } } + } } diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt index 93953be6f9..ea81d27470 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt @@ -5,6 +5,7 @@ using System.Reflection; [assembly: AssemblyFileVersion("1.2.3.0")] [assembly: AssemblyInformationalVersion("1.2.3-unstable.4+5.Branch.feature1.Sha.commitSha")] [assembly: Fake.ReleaseDate("2014-03-06")] +[assembly: Fake.GitVersionInformation()] namespace Fake { @@ -42,4 +43,28 @@ namespace Fake public static string NuGetVersion = "1.2.3-unstable0004"; public static string CommitDate = "2014-03-06"; } + + [System.Runtime.CompilerServices.CompilerGenerated] + sealed class GitVersionInformationAttribute : System.Attribute + { + public string Major { get { return "1"; } } + public string Minor { get { return "2"; } } + public string Patch { get { return "3"; } } + public string PreReleaseTag { get { return "unstable.4"; } } + public string PreReleaseTagWithDash { get { return "-unstable.4"; } } + public string BuildMetaData { get { return "5"; } } + public string FullBuildMetaData { get { return "5.Branch.feature1.Sha.commitSha"; } } + public string MajorMinorPatch { get { return "1.2.3"; } } + public string SemVer { get { return "1.2.3-unstable.4"; } } + public string LegacySemVer { get { return "1.2.3-unstable4"; } } + public string LegacySemVerPadded { get { return "1.2.3-unstable0004"; } } + public string AssemblySemVer { get { return "1.2.3.0"; } } + public string FullSemVer { get { return "1.2.3-unstable.4+5"; } } + public string InformationalVersion { get { return "1.2.3-unstable.4+5.Branch.feature1.Sha.commitSha"; } } + public string BranchName { get { return "feature1"; } } + public string Sha { get { return "commitSha"; } } + public string NuGetVersionV2 { get { return "1.2.3-unstable0004"; } } + public string NuGetVersion { get { return "1.2.3-unstable0004"; } } + public string CommitDate { get { return "2014-03-06"; } } + } } diff --git a/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs b/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs index 59407657be..e57b292ff7 100644 --- a/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs +++ b/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs @@ -17,9 +17,10 @@ public string GetAssemblyInfoText(VersionVariables vars, string assemblyName) [assembly: AssemblyVersion(""{0}"")] [assembly: AssemblyFileVersion(""{1}"")] [assembly: AssemblyInformationalVersion(""{2}"")] -[assembly: {5}.ReleaseDate(""{3}"")] +[assembly: {6}.ReleaseDate(""{3}"")] +[assembly: {6}.GitVersionInformation()] -namespace {5} +namespace {6} {{ [System.Runtime.CompilerServices.CompilerGenerated] sealed class ReleaseDateAttribute : System.Attribute @@ -37,19 +38,26 @@ static class GitVersionInformation {{ {4} }} + + [System.Runtime.CompilerServices.CompilerGenerated] + sealed class GitVersionInformationAttribute : System.Attribute + {{ +{5} + }} }} ", vars.AssemblySemVer, vars.MajorMinorPatch + ".0", vars.InformationalVersion, vars.CommitDate, - GenerateVariableMembers(v), + GenerateStaticVariableMembers(v), + GenerateAttributeVariableMembers(v), assemblyName); return assemblyInfo; } - static string GenerateVariableMembers(IList> vars) + static string GenerateStaticVariableMembers(IList> vars) { var members = new StringBuilder(); for (var i = 0; i < vars.Count; i++) @@ -65,4 +73,22 @@ static string GenerateVariableMembers(IList> vars) return members.ToString(); } + + + static string GenerateAttributeVariableMembers(IList> vars) + { + var members = new StringBuilder(); + for (var i = 0; i < vars.Count; i++) + { + var variable = vars[i]; + members.AppendFormat(" public string {0} {{ get {{ return \"{1}\"; }} }}", variable.Key, variable.Value); + + if (i < vars.Count - 1) + { + members.AppendLine(); + } + } + + return members.ToString(); + } } \ No newline at end of file From 6730964f824644305fbed0dcf5dd2e825a8dd74e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Tue, 21 Jul 2015 17:03:55 +0200 Subject: [PATCH 4/9] Add [AttributeUsage(AttributeTargets.Assembly)] to the custom assembly attributes so they are easier to find. --- ...blyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt | 2 ++ ...foBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt | 2 ++ ...lderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt | 2 ++ ...rTests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt | 2 ++ .../AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt | 2 ++ src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs | 2 ++ 6 files changed, 12 insertions(+) diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt index 438b8c0d6e..8afb8fa2fd 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt @@ -10,6 +10,7 @@ using System.Reflection; namespace Fake { [System.Runtime.CompilerServices.CompilerGenerated] +[AttributeUsage(AttributeTargets.Assembly)] sealed class ReleaseDateAttribute : System.Attribute { public string Date { get; private set; } @@ -45,6 +46,7 @@ namespace Fake } [System.Runtime.CompilerServices.CompilerGenerated] +[AttributeUsage(AttributeTargets.Assembly)] sealed class GitVersionInformationAttribute : System.Attribute { public string Major { get { return "2"; } } diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt index e6ab7a1a84..75c76b7888 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt @@ -10,6 +10,7 @@ using System.Reflection; namespace Fake { [System.Runtime.CompilerServices.CompilerGenerated] +[AttributeUsage(AttributeTargets.Assembly)] sealed class ReleaseDateAttribute : System.Attribute { public string Date { get; private set; } @@ -45,6 +46,7 @@ namespace Fake } [System.Runtime.CompilerServices.CompilerGenerated] +[AttributeUsage(AttributeTargets.Assembly)] sealed class GitVersionInformationAttribute : System.Attribute { public string Major { get { return "2"; } } diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt index d567a1ab52..98f3d31d58 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt @@ -10,6 +10,7 @@ using System.Reflection; namespace Fake { [System.Runtime.CompilerServices.CompilerGenerated] +[AttributeUsage(AttributeTargets.Assembly)] sealed class ReleaseDateAttribute : System.Attribute { public string Date { get; private set; } @@ -45,6 +46,7 @@ namespace Fake } [System.Runtime.CompilerServices.CompilerGenerated] +[AttributeUsage(AttributeTargets.Assembly)] sealed class GitVersionInformationAttribute : System.Attribute { public string Major { get { return "2"; } } diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt index c5a67c035f..024e3dac1e 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt @@ -10,6 +10,7 @@ using System.Reflection; namespace Fake { [System.Runtime.CompilerServices.CompilerGenerated] +[AttributeUsage(AttributeTargets.Assembly)] sealed class ReleaseDateAttribute : System.Attribute { public string Date { get; private set; } @@ -45,6 +46,7 @@ namespace Fake } [System.Runtime.CompilerServices.CompilerGenerated] +[AttributeUsage(AttributeTargets.Assembly)] sealed class GitVersionInformationAttribute : System.Attribute { public string Major { get { return "2"; } } diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt index ea81d27470..9cb92ca291 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt @@ -10,6 +10,7 @@ using System.Reflection; namespace Fake { [System.Runtime.CompilerServices.CompilerGenerated] +[AttributeUsage(AttributeTargets.Assembly)] sealed class ReleaseDateAttribute : System.Attribute { public string Date { get; private set; } @@ -45,6 +46,7 @@ namespace Fake } [System.Runtime.CompilerServices.CompilerGenerated] +[AttributeUsage(AttributeTargets.Assembly)] sealed class GitVersionInformationAttribute : System.Attribute { public string Major { get { return "1"; } } diff --git a/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs b/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs index e57b292ff7..01eeaa29dc 100644 --- a/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs +++ b/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs @@ -23,6 +23,7 @@ public string GetAssemblyInfoText(VersionVariables vars, string assemblyName) namespace {6} {{ [System.Runtime.CompilerServices.CompilerGenerated] +[AttributeUsage(AttributeTargets.Assembly)] sealed class ReleaseDateAttribute : System.Attribute {{ public string Date {{ get; private set; }} @@ -40,6 +41,7 @@ static class GitVersionInformation }} [System.Runtime.CompilerServices.CompilerGenerated] +[AttributeUsage(AttributeTargets.Assembly)] sealed class GitVersionInformationAttribute : System.Attribute {{ {5} From 8b82d78d707d27aa056ac4a1496c66c2ca81fa54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Tue, 21 Jul 2015 17:15:40 +0200 Subject: [PATCH 5/9] Verify that the generated assembly info contains the GitVersionInformationAttribute and that it has the correct values. --- .../AssemblyInfoBuilderTests.cs | 41 +++++++++++++++++-- .../AssemblyInfoBuilder.cs | 4 +- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.cs b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.cs index 7f9dc7969d..8b2cc9e812 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.cs +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.cs @@ -1,6 +1,7 @@ using System; using System.IO; using System.Linq; +using System.Reflection; using System.Runtime.CompilerServices; using ApprovalTests; using GitVersion; @@ -29,12 +30,20 @@ public void VerifyCreatedCode() Approvals.Verify(assemblyInfoText); var compilation = CSharpCompilation.Create("Fake.dll") - .WithOptions(new CSharpCompilationOptions(OutputKind.NetModule)) + .WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)) .AddReferences(MetadataReference.CreateFromFile(typeof(object).Assembly.Location)) .AddSyntaxTrees(CSharpSyntaxTree.ParseText(assemblyInfoText)); - var emitResult = compilation.Emit(new MemoryStream()); - Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Descriptor))); + using (var stream = new MemoryStream()) + { + var emitResult = compilation.Emit(stream); + + Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Descriptor))); + + stream.Seek(0, SeekOrigin.Begin); + var assembly = Assembly.Load(stream.ToArray()); + VerifyGitVersionInformationAttribute(assembly, versionVariables); + } } [Test] @@ -89,4 +98,30 @@ static void VerifyAssemblyVersion(AssemblyVersioningScheme avs) var emitResult = compilation.Emit(new MemoryStream()); Assert.IsTrue(emitResult.Success, string.Join(Environment.NewLine, emitResult.Diagnostics.Select(x => x.Descriptor))); } + + static void VerifyGitVersionInformationAttribute(Assembly assembly, VersionVariables versionVariables) + { + var gitVersionInformationAttributeData = assembly.CustomAttributes + .FirstOrDefault(a => a.AttributeType.Name == "GitVersionInformationAttribute"); + + Assert.IsNotNull(gitVersionInformationAttributeData); + + var gitVersionInformationAttributeType = gitVersionInformationAttributeData.AttributeType; + var gitVersionInformationAttribute = assembly + .GetCustomAttributes(gitVersionInformationAttributeType) + .FirstOrDefault(); + + Assert.IsNotNull(gitVersionInformationAttribute); + + var properties = gitVersionInformationAttributeType.GetProperties(BindingFlags.Instance | BindingFlags.Public); + + foreach (var variable in versionVariables) + { + var property = properties.FirstOrDefault(p => p.Name == variable.Key); + Assert.IsNotNull(property); + + var propertyValue = property.GetValue(gitVersionInformationAttribute, null); + Assert.AreEqual(variable.Value, propertyValue, "{0} had an invalid value.", property.Name); + } + } } \ No newline at end of file diff --git a/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs b/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs index 01eeaa29dc..6abcdb92bf 100644 --- a/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs +++ b/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs @@ -23,7 +23,7 @@ public string GetAssemblyInfoText(VersionVariables vars, string assemblyName) namespace {6} {{ [System.Runtime.CompilerServices.CompilerGenerated] -[AttributeUsage(AttributeTargets.Assembly)] + [AttributeUsage(AttributeTargets.Assembly)] sealed class ReleaseDateAttribute : System.Attribute {{ public string Date {{ get; private set; }} @@ -41,7 +41,7 @@ static class GitVersionInformation }} [System.Runtime.CompilerServices.CompilerGenerated] -[AttributeUsage(AttributeTargets.Assembly)] + [AttributeUsage(AttributeTargets.Assembly)] sealed class GitVersionInformationAttribute : System.Attribute {{ {5} From 68fa1266bc5fe08a3da25c4957aa9c34e5b689ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Asbj=C3=B8rn=20Ulsberg?= Date: Tue, 21 Jul 2015 17:21:42 +0200 Subject: [PATCH 6/9] Just be sure that none of the variables we're comparing against are `null`, since that would make the verification kind of pointless. --- src/GitVersionTask.Tests/AssemblyInfoBuilderTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.cs b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.cs index 8b2cc9e812..8b985cc287 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.cs +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.cs @@ -117,6 +117,8 @@ static void VerifyGitVersionInformationAttribute(Assembly assembly, VersionVaria foreach (var variable in versionVariables) { + Assert.IsNotNull(variable.Value); + var property = properties.FirstOrDefault(p => p.Name == variable.Key); Assert.IsNotNull(property); From 42e0e82434a02c3e683c0880b08025137f3f1a2a Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Wed, 22 Jul 2015 10:42:10 +0800 Subject: [PATCH 7/9] Removed duplication in member formatting --- .../AssemblyInfoBuilder.cs | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs b/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs index 6abcdb92bf..3f19af53cc 100644 --- a/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs +++ b/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs @@ -61,29 +61,22 @@ sealed class GitVersionInformationAttribute : System.Attribute static string GenerateStaticVariableMembers(IList> vars) { - var members = new StringBuilder(); - for (var i = 0; i < vars.Count; i++) - { - var variable = vars[i]; - members.AppendFormat(" public static string {0} = \"{1}\";", variable.Key, variable.Value); - - if (i < vars.Count - 1) - { - members.AppendLine(); - } - } - - return members.ToString(); + return GenerateMembers(vars, " public static string {0} = \"{1}\";"); } static string GenerateAttributeVariableMembers(IList> vars) + { + return GenerateMembers(vars, " public string {0} {{ get {{ return \"{1}\"; }} }}"); + } + + static string GenerateMembers(IList> vars, string memberFormat) { var members = new StringBuilder(); for (var i = 0; i < vars.Count; i++) { var variable = vars[i]; - members.AppendFormat(" public string {0} {{ get {{ return \"{1}\"; }} }}", variable.Key, variable.Value); + members.AppendFormat(memberFormat, variable.Key, variable.Value); if (i < vars.Count - 1) { From 79b39747bafe94a70f4596566a5f6a120350e49c Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Wed, 22 Jul 2015 10:42:42 +0800 Subject: [PATCH 8/9] Simplified generate members function --- .../AssemblyInfoBuilder.cs | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs b/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs index 3f19af53cc..6b36578f72 100644 --- a/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs +++ b/src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs @@ -1,14 +1,13 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; -using System.Text; - using GitVersion; public class AssemblyInfoBuilder { public string GetAssemblyInfoText(VersionVariables vars, string assemblyName) { - var v = vars.ToArray(); + var v = vars.ToList(); var assemblyInfo = string.Format( @"using System; @@ -72,18 +71,6 @@ static string GenerateAttributeVariableMembers(IList> vars, string memberFormat) { - var members = new StringBuilder(); - for (var i = 0; i < vars.Count; i++) - { - var variable = vars[i]; - members.AppendFormat(memberFormat, variable.Key, variable.Value); - - if (i < vars.Count - 1) - { - members.AppendLine(); - } - } - - return members.ToString(); + return string.Join(Environment.NewLine, vars.Select(v => string.Format(memberFormat, v.Key, v.Value))); } } \ No newline at end of file From 86133648cb54e9a5b2368c1740e0630994b3ccac Mon Sep 17 00:00:00 2001 From: Jake Ginnivan Date: Wed, 22 Jul 2015 10:47:03 +0800 Subject: [PATCH 9/9] Fixed formatting in approved --- ...yInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt | 4 ++-- ...BuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt | 4 ++-- ...erTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt | 4 ++-- ...ests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt | 4 ++-- .../AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt index 8afb8fa2fd..3f1eccb9ac 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_Major.approved.txt @@ -10,7 +10,7 @@ using System.Reflection; namespace Fake { [System.Runtime.CompilerServices.CompilerGenerated] -[AttributeUsage(AttributeTargets.Assembly)] + [AttributeUsage(AttributeTargets.Assembly)] sealed class ReleaseDateAttribute : System.Attribute { public string Date { get; private set; } @@ -46,7 +46,7 @@ namespace Fake } [System.Runtime.CompilerServices.CompilerGenerated] -[AttributeUsage(AttributeTargets.Assembly)] + [AttributeUsage(AttributeTargets.Assembly)] sealed class GitVersionInformationAttribute : System.Attribute { public string Major { get { return "2"; } } diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt index 75c76b7888..24aa7e48fd 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinor.approved.txt @@ -10,7 +10,7 @@ using System.Reflection; namespace Fake { [System.Runtime.CompilerServices.CompilerGenerated] -[AttributeUsage(AttributeTargets.Assembly)] + [AttributeUsage(AttributeTargets.Assembly)] sealed class ReleaseDateAttribute : System.Attribute { public string Date { get; private set; } @@ -46,7 +46,7 @@ namespace Fake } [System.Runtime.CompilerServices.CompilerGenerated] -[AttributeUsage(AttributeTargets.Assembly)] + [AttributeUsage(AttributeTargets.Assembly)] sealed class GitVersionInformationAttribute : System.Attribute { public string Major { get { return "2"; } } diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt index 98f3d31d58..cf12fed4c2 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatch.approved.txt @@ -10,7 +10,7 @@ using System.Reflection; namespace Fake { [System.Runtime.CompilerServices.CompilerGenerated] -[AttributeUsage(AttributeTargets.Assembly)] + [AttributeUsage(AttributeTargets.Assembly)] sealed class ReleaseDateAttribute : System.Attribute { public string Date { get; private set; } @@ -46,7 +46,7 @@ namespace Fake } [System.Runtime.CompilerServices.CompilerGenerated] -[AttributeUsage(AttributeTargets.Assembly)] + [AttributeUsage(AttributeTargets.Assembly)] sealed class GitVersionInformationAttribute : System.Attribute { public string Major { get { return "2"; } } diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt index 024e3dac1e..4e3625433d 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyAssemblyVersion_MajorMinorPatchTag.approved.txt @@ -10,7 +10,7 @@ using System.Reflection; namespace Fake { [System.Runtime.CompilerServices.CompilerGenerated] -[AttributeUsage(AttributeTargets.Assembly)] + [AttributeUsage(AttributeTargets.Assembly)] sealed class ReleaseDateAttribute : System.Attribute { public string Date { get; private set; } @@ -46,7 +46,7 @@ namespace Fake } [System.Runtime.CompilerServices.CompilerGenerated] -[AttributeUsage(AttributeTargets.Assembly)] + [AttributeUsage(AttributeTargets.Assembly)] sealed class GitVersionInformationAttribute : System.Attribute { public string Major { get { return "2"; } } diff --git a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt index 9cb92ca291..08e0314438 100644 --- a/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt +++ b/src/GitVersionTask.Tests/AssemblyInfoBuilderTests.VerifyCreatedCode.approved.txt @@ -10,7 +10,7 @@ using System.Reflection; namespace Fake { [System.Runtime.CompilerServices.CompilerGenerated] -[AttributeUsage(AttributeTargets.Assembly)] + [AttributeUsage(AttributeTargets.Assembly)] sealed class ReleaseDateAttribute : System.Attribute { public string Date { get; private set; } @@ -46,7 +46,7 @@ namespace Fake } [System.Runtime.CompilerServices.CompilerGenerated] -[AttributeUsage(AttributeTargets.Assembly)] + [AttributeUsage(AttributeTargets.Assembly)] sealed class GitVersionInformationAttribute : System.Attribute { public string Major { get { return "1"; } }