Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add contents of AssemblyInformationalVersionAttribute to the AssemblyVersionInformation class #1183

Merged
merged 3 commits into from
Mar 31, 2016
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
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