Skip to content

Commit

Permalink
Merge pull request #1183 from amazingant/master
Browse files Browse the repository at this point in the history
Add contents of `AssemblyInformationalVersionAttribute` to the `AssemblyVersionInformation` class
  • Loading branch information
forki committed Mar 31, 2016
2 parents 436b6be + 41409e2 commit 8eafec9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 10 additions & 1 deletion src/app/FakeLib/AssemblyInfoFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ let private getAssemblyVersionInfo attributes =
| Some attr -> attr.Value
| None _ -> "\"" + buildVersion + "\""

let private getAssemblyInformationalVersion attributes =
match attributes |> Seq.tryFind (fun (attr : Attribute) -> attr.Name = "AssemblyInformationalVersion") with
| Some attr -> attr.Value
| None _ -> getAssemblyVersionInfo attributes

/// Creates a C# AssemblyInfo file with the given attributes and configuration.
/// The generated AssemblyInfo file contains an AssemblyVersionInformation class which can be used to retrieve the current version no. from inside of an assembly.
let CreateCSharpAssemblyInfoWithConfig outputFileName attributes (config : AssemblyInfoFileConfig) =
Expand All @@ -168,6 +173,7 @@ let CreateCSharpAssemblyInfoWithConfig outputFileName attributes (config : Assem
[ sprintf "namespace %s {" useNamespace
" internal static class AssemblyVersionInformation {"
sprintf " internal const string Version = %s;" (getAssemblyVersionInfo attributes)
sprintf " internal const string InformationalVersion = %s;" (getAssemblyInformationalVersion attributes)
" }"
"}" ]
else []
Expand All @@ -194,7 +200,9 @@ let CreateFSharpAssemblyInfoWithConfig outputFileName attributes (config : Assem

let optional =
[ "module internal AssemblyVersionInformation ="
sprintf " let [<Literal>] Version = %s" (getAssemblyVersionInfo attributes) ]
sprintf " let [<Literal>] Version = %s" (getAssemblyVersionInfo attributes)
sprintf " let [<Literal>] InformationalVersion = %s" (getAssemblyInformationalVersion attributes)
]

if generateClass then required @ optional
else required
Expand All @@ -218,6 +226,7 @@ let CreateVisualBasicAssemblyInfoWithConfig outputFileName attributes (config :
if generateClass then
[ "Friend NotInheritable Class AssemblyVersionInformation"
sprintf " Friend Const Version As String = %s" (getAssemblyVersionInfo attributes)
sprintf " Friend Const InformationalVersion As String = %s" (getAssemblyInformationalVersion attributes)
"End Class" ]
else []

Expand Down
6 changes: 3 additions & 3 deletions src/test/Test.FAKECore/AssemblyInfoSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class when_using_fsharp_task_with_default_config
AssemblyInfoFile.Attribute.Version("1.0.0.0")
};
AssemblyInfoFile.CreateFSharpAssemblyInfo(infoFile, attributes);
const string expected = "namespace System\r\nopen System.Reflection\r\n\r\n[<assembly: AssemblyProductAttribute(\"TestLib\")>]\r\n[<assembly: AssemblyVersionAttribute(\"1.0.0.0\")>]\r\ndo ()\r\n\r\nmodule internal AssemblyVersionInformation =\r\n let [<Literal>] Version = \"1.0.0.0\"\r\n";
const string expected = "namespace System\r\nopen System.Reflection\r\n\r\n[<assembly: AssemblyProductAttribute(\"TestLib\")>]\r\n[<assembly: AssemblyVersionAttribute(\"1.0.0.0\")>]\r\ndo ()\r\n\r\nmodule internal AssemblyVersionInformation =\r\n let [<Literal>] Version = \"1.0.0.0\"\r\n let [<Literal>] InformationalVersion = \"1.0.0.0\"\r\n";

File.ReadAllText(infoFile)
.ShouldEqual(expected.Replace("\r\n", Environment.NewLine));
Expand Down Expand Up @@ -104,7 +104,7 @@ public class when_using_csharp_task_with_default_config
AssemblyInfoFile.Attribute.Version("1.0.0.0")
};
AssemblyInfoFile.CreateCSharpAssemblyInfo(infoFile, attributes);
const string expected = "// <auto-generated/>\r\nusing System.Reflection;\r\n\r\n[assembly: AssemblyProductAttribute(\"TestLib\")]\r\n[assembly: AssemblyVersionAttribute(\"1.0.0.0\")]\r\nnamespace System {\r\n internal static class AssemblyVersionInformation {\r\n internal const string Version = \"1.0.0.0\";\r\n }\r\n}\r\n";
const string expected = "// <auto-generated/>\r\nusing System.Reflection;\r\n\r\n[assembly: AssemblyProductAttribute(\"TestLib\")]\r\n[assembly: AssemblyVersionAttribute(\"1.0.0.0\")]\r\nnamespace System {\r\n internal static class AssemblyVersionInformation {\r\n internal const string Version = \"1.0.0.0\";\r\n internal const string InformationalVersion = \"1.0.0.0\";\r\n }\r\n}\r\n";

File.ReadAllText(infoFile)
.ShouldEqual(expected.Replace("\r\n", Environment.NewLine));
Expand Down Expand Up @@ -230,7 +230,7 @@ public class when_using_vb_task_with_default_config
AssemblyInfoFile.Attribute.Version("1.0.0.0")
};
AssemblyInfoFile.CreateVisualBasicAssemblyInfo(infoFile, attributes);
const string expected = "' <auto-generated/>\r\nImports System.Reflection\r\n\r\n<assembly: AssemblyProductAttribute(\"TestLib\")>\r\n<assembly: AssemblyVersionAttribute(\"1.0.0.0\")>\r\nFriend NotInheritable Class AssemblyVersionInformation\r\n Friend Const Version As String = \"1.0.0.0\"\r\nEnd Class\r\n";
const string expected = "' <auto-generated/>\r\nImports System.Reflection\r\n\r\n<assembly: AssemblyProductAttribute(\"TestLib\")>\r\n<assembly: AssemblyVersionAttribute(\"1.0.0.0\")>\r\nFriend NotInheritable Class AssemblyVersionInformation\r\n Friend Const Version As String = \"1.0.0.0\"\r\n Friend Const InformationalVersion As String = \"1.0.0.0\"\r\nEnd Class\r\n";

File.ReadAllText(infoFile)
.ShouldEqual(expected.Replace("\r\n", Environment.NewLine));
Expand Down

0 comments on commit 8eafec9

Please sign in to comment.