Skip to content

Commit

Permalink
Touch ups
Browse files Browse the repository at this point in the history
  • Loading branch information
AArnott committed Nov 24, 2018
1 parent 1594cb3 commit 0fc0444
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
14 changes: 7 additions & 7 deletions src/NerdBank.GitVersioning.Tests/AssemblyInfoTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public void FSharpGenerator()
{
var info = new AssemblyVersionInfo();
info.AssemblyCompany = "company";
info.AssemblyFileVersion = "1.3";
info.AssemblyVersion = "1.3.0";
info.AssemblyFileVersion = "1.3.1.0";
info.AssemblyVersion = "1.3.0.0";
info.CodeLanguage = "f#";

var built = info.BuildCode();
Expand All @@ -31,14 +31,14 @@ public void FSharpGenerator()
// </auto-generated>
//------------------------------------------------------------------------------
namespace AssemblyInfo.Properties
[<assembly: System.Reflection.AssemblyVersionAttribute(""1.3.0"")>]
[<assembly: System.Reflection.AssemblyFileVersionAttribute(""1.3"")>]
namespace AssemblyInfo
[<assembly: System.Reflection.AssemblyVersionAttribute(""1.3.0.0"")>]
[<assembly: System.Reflection.AssemblyFileVersionAttribute(""1.3.1.0"")>]
[<assembly: System.Reflection.AssemblyInformationalVersionAttribute("""")>]
do()
type internal ThisAssembly() =
static member internal AssemblyVersion = ""1.3.0""
static member internal AssemblyFileVersion = ""1.3""
static member internal AssemblyVersion = ""1.3.0.0""
static member internal AssemblyFileVersion = ""1.3.1.0""
static member internal AssemblyCompany = ""company""
static member internal RootNamespace = """"
do()
Expand Down
23 changes: 14 additions & 9 deletions src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ the code is regenerated.
";

private CodeGenerator generator;

[Required]
public string CodeLanguage { get; set; }

Expand Down Expand Up @@ -105,6 +105,10 @@ public override bool Execute()
Directory.CreateDirectory(Path.GetDirectoryName(this.OutputFile));
Utilities.FileOperationWithRetry(() => File.WriteAllText(this.OutputFile, fileContent));
}
else
{
this.Log.LogError("CodeDomProvider not available for language: {0}. No version info will be embedded into assembly.", this.CodeLanguage);
}
}

return !this.Log.HasLoggedErrors;
Expand Down Expand Up @@ -227,10 +231,9 @@ public string BuildCode()
{
this.generator.AddComment(FileHeaderComment);
this.generator.AddBlankLine();
this.generator.StartNamespace(this.RootNamespace ?? "AssemblyInfo");
this.generator.EmitNamespaceIfRequired(this.RootNamespace ?? "AssemblyInfo");
this.GenerateAssemblyAttributes();
this.GenerateThisAssemblyClass();
this.generator.EndNamespace();
return this.generator.GetCode();
}
return null;
Expand Down Expand Up @@ -294,6 +297,7 @@ private void GenerateThisAssemblyClass()

this.generator.EndThisAssemblyClass();
}

private CodeGenerator CreateGenerator()
{
switch (this.CodeLanguage.ToLowerInvariant())
Expand Down Expand Up @@ -331,9 +335,11 @@ internal CodeGenerator()

internal abstract void EndThisAssemblyClass();

internal virtual void StartNamespace(string ns) { }

internal virtual void EndNamespace() { }
/// <summary>
/// Gives languages that *require* a namespace a chance to emit such.
/// </summary>
/// <param name="ns">The RootNamespace of the project.</param>
internal virtual void EmitNamespaceIfRequired(string ns) { }

internal string GetCode() => this.codeBuilder.ToString();

Expand Down Expand Up @@ -366,9 +372,9 @@ internal override void AddThisAssemblyMember(string name, string value)
this.codeBuilder.AppendLine($" static member internal {name} = \"{value}\"");
}

internal override void StartNamespace(string ns)
internal override void EmitNamespaceIfRequired(string ns)
{
this.codeBuilder.AppendLine($"namespace {ns}.Properties");
this.codeBuilder.AppendLine($"namespace {ns}");
}

internal override void DeclareAttribute(Type type, string arg)
Expand Down Expand Up @@ -442,7 +448,6 @@ internal override void EndThisAssemblyClass()
this.codeBuilder.AppendLine("End Class");
}
}
//#endif

private static string ToHex(byte[] data)
{
Expand Down

0 comments on commit 0fc0444

Please sign in to comment.