Skip to content

Commit eb01f07

Browse files
authored
Merge pull request #1190 from BeyondFold/feature/issue-138
Support generating F# AssemblyVersion attributes
2 parents 38f7036 + dc81d9a commit eb01f07

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed

src/GitVersionTask.Tests/AssemblyInfoBuilderTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,10 @@ public void GetAssemblyInfoBuilder_Null_ThrowsArgumentNullException()
232232

233233
[TestCase("Class1.cs", typeof(CSharpAssemblyInfoBuilder))]
234234
[TestCase("Class1.vb", typeof(VisualBasicAssemblyInfoBuilder))]
235+
[TestCase("Class1.fs", typeof(FSharpAssemblyInfoBuilder))]
235236
[TestCase("AssemblyInfo.cs", typeof(CSharpAssemblyInfoBuilder))]
236237
[TestCase("AssemblyInfo.vb", typeof(VisualBasicAssemblyInfoBuilder))]
238+
[TestCase("AssemblyInfo.fs", typeof(FSharpAssemblyInfoBuilder))]
237239
public void GetAssemblyInfoBuilder_ShouldReturnAppropriateAssemblyInfoBuilder(string fileName, Type assemblyInfoBuilderType)
238240
{
239241
var taskItem = Substitute.For<ITaskItem>();

src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ public abstract class AssemblyInfoBuilder
1111
private static readonly Dictionary<string, Type> assemblyInfoBuilders = new Dictionary<string, Type>
1212
{
1313
{".cs", typeof(CSharpAssemblyInfoBuilder)},
14-
{".vb", typeof(VisualBasicAssemblyInfoBuilder)}
15-
// TODO: Missing FSharpAssemblyInfoBuilder
14+
{".vb", typeof(VisualBasicAssemblyInfoBuilder)},
15+
{".fs", typeof(FSharpAssemblyInfoBuilder)},
1616
};
1717

1818
public abstract string AssemblyInfoExtension { get; }
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using GitVersion;
5+
6+
public class FSharpAssemblyInfoBuilder : AssemblyInfoBuilder
7+
{
8+
public override string AssemblyInfoExtension { get { return "fs"; } }
9+
10+
public override string GetAssemblyInfoText(VersionVariables vars, string rootNamespace)
11+
{
12+
var v = vars.ToList();
13+
14+
// TODO: Consolidate this with GitVersion.VersionAssemblyInfoResources.AssemblyVersionInfoTemplates. @asbjornu
15+
var assemblyInfo = string.Format(
16+
@"//------------------------------------------------------------------------------
17+
// <auto-generated>
18+
// This code was generated by a tool.
19+
// GitVersion
20+
//
21+
// Changes to this file may cause incorrect behavior and will be lost if
22+
// the code is regenerated.
23+
// </auto-generated>
24+
//------------------------------------------------------------------------------
25+
26+
namespace {4}
27+
28+
open System
29+
open System.Reflection
30+
31+
[<assembly: AssemblyVersion(""{0}"")>]
32+
[<assembly: AssemblyFileVersion(""{1}"")>]
33+
[<assembly: AssemblyInformationalVersion(""{2}"")>]
34+
35+
do
36+
()
37+
38+
[<AbstractClass; Sealed>]
39+
[<global.System.Runtime.CompilerServices.CompilerGenerated>]
40+
module GitVersionInformation =
41+
{3}
42+
",
43+
vars.AssemblySemVer,
44+
vars.MajorMinorPatch + ".0",
45+
vars.InformationalVersion,
46+
GenerateStaticVariableMembers(v),
47+
rootNamespace);
48+
49+
return assemblyInfo;
50+
}
51+
52+
static string GenerateStaticVariableMembers(IList<KeyValuePair<string, string>> vars)
53+
{
54+
return GenerateMembers(vars, " let {0} = \"{1}\"");
55+
}
56+
57+
58+
static string GenerateMembers(IList<KeyValuePair<string, string>> vars, string memberFormat)
59+
{
60+
return string.Join(Environment.NewLine, vars.Select(v => string.Format(memberFormat, v.Key, v.Value)));
61+
}
62+
}

src/GitVersionTask/GitVersionTask.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
</ItemGroup>
6666
<ItemGroup>
6767
<Compile Include="AssemblyInfoBuilder\AssemblyInfoBuilder.cs" />
68+
<Compile Include="AssemblyInfoBuilder\FSharpAssemblyInfoBuilder.cs" />
6869
<Compile Include="AssemblyInfoBuilder\VisualBasicAssemblyInfoBuilder.cs" />
6970
<Compile Include="AssemblyInfoBuilder\CSharpAssemblyInfoBuilder.cs" />
7071
<Compile Include="BuildLogger.cs" />

0 commit comments

Comments
 (0)