Skip to content

Support generating F# AssemblyVersion attributes #1190

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

Merged
merged 2 commits into from
Apr 24, 2017
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: 2 additions & 0 deletions src/GitVersionTask.Tests/AssemblyInfoBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,10 @@ public void GetAssemblyInfoBuilder_Null_ThrowsArgumentNullException()

[TestCase("Class1.cs", typeof(CSharpAssemblyInfoBuilder))]
[TestCase("Class1.vb", typeof(VisualBasicAssemblyInfoBuilder))]
[TestCase("Class1.fs", typeof(FSharpAssemblyInfoBuilder))]
[TestCase("AssemblyInfo.cs", typeof(CSharpAssemblyInfoBuilder))]
[TestCase("AssemblyInfo.vb", typeof(VisualBasicAssemblyInfoBuilder))]
[TestCase("AssemblyInfo.fs", typeof(FSharpAssemblyInfoBuilder))]
public void GetAssemblyInfoBuilder_ShouldReturnAppropriateAssemblyInfoBuilder(string fileName, Type assemblyInfoBuilderType)
{
var taskItem = Substitute.For<ITaskItem>();
Expand Down
4 changes: 2 additions & 2 deletions src/GitVersionTask/AssemblyInfoBuilder/AssemblyInfoBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public abstract class AssemblyInfoBuilder
private static readonly Dictionary<string, Type> assemblyInfoBuilders = new Dictionary<string, Type>
{
{".cs", typeof(CSharpAssemblyInfoBuilder)},
{".vb", typeof(VisualBasicAssemblyInfoBuilder)}
// TODO: Missing FSharpAssemblyInfoBuilder
{".vb", typeof(VisualBasicAssemblyInfoBuilder)},
{".fs", typeof(FSharpAssemblyInfoBuilder)},
};

public abstract string AssemblyInfoExtension { get; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GitVersion;

public class FSharpAssemblyInfoBuilder : AssemblyInfoBuilder
{
public override string AssemblyInfoExtension { get { return "fs"; } }

public override string GetAssemblyInfoText(VersionVariables vars, string rootNamespace)
{
var v = vars.ToList();

// TODO: Consolidate this with GitVersion.VersionAssemblyInfoResources.AssemblyVersionInfoTemplates. @asbjornu
var assemblyInfo = string.Format(
@"//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// GitVersion
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

namespace {4}

open System
open System.Reflection

[<assembly: AssemblyVersion(""{0}"")>]
[<assembly: AssemblyFileVersion(""{1}"")>]
[<assembly: AssemblyInformationalVersion(""{2}"")>]

do
()

[<AbstractClass; Sealed>]
[<global.System.Runtime.CompilerServices.CompilerGenerated>]
module GitVersionInformation =
{3}
",
vars.AssemblySemVer,
vars.MajorMinorPatch + ".0",
vars.InformationalVersion,
GenerateStaticVariableMembers(v),
rootNamespace);

return assemblyInfo;
}

static string GenerateStaticVariableMembers(IList<KeyValuePair<string, string>> vars)
{
return GenerateMembers(vars, " let {0} = \"{1}\"");
}


static string GenerateMembers(IList<KeyValuePair<string, string>> vars, string memberFormat)
{
return string.Join(Environment.NewLine, vars.Select(v => string.Format(memberFormat, v.Key, v.Value)));
}
}
1 change: 1 addition & 0 deletions src/GitVersionTask/GitVersionTask.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfoBuilder\AssemblyInfoBuilder.cs" />
<Compile Include="AssemblyInfoBuilder\FSharpAssemblyInfoBuilder.cs" />
<Compile Include="AssemblyInfoBuilder\VisualBasicAssemblyInfoBuilder.cs" />
<Compile Include="AssemblyInfoBuilder\CSharpAssemblyInfoBuilder.cs" />
<Compile Include="BuildLogger.cs" />
Expand Down