Skip to content

Commit

Permalink
Prefer manual code generation over CodeDOM
Browse files Browse the repository at this point in the history
CodeDOM is *very* slow, it turns out.

Addresses on eof the perf issues reported in #114
  • Loading branch information
AArnott committed Feb 28, 2019
1 parent 4674c27 commit c0ce4fc
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions src/Nerdbank.GitVersioning.Tasks/AssemblyVersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ public class AssemblyVersionInfo : Task
#if NET461
public override bool Execute()
{
if (CodeDomProvider.IsDefinedLanguage(this.CodeLanguage))
// attempt to use local codegen
string fileContent = this.BuildCode();
if (fileContent != null)
{
Directory.CreateDirectory(Path.GetDirectoryName(this.OutputFile));
Utilities.FileOperationWithRetry(() => File.WriteAllText(this.OutputFile, fileContent));
}
else if (CodeDomProvider.IsDefinedLanguage(this.CodeLanguage))
{
using (var codeDomProvider = CodeDomProvider.CreateProvider(this.CodeLanguage))
{
Expand Down Expand Up @@ -100,17 +107,7 @@ public override bool Execute()
}
else
{
// attempt to use local codegen
string fileContent = this.BuildCode();
if (fileContent != null)
{
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);
}
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

0 comments on commit c0ce4fc

Please sign in to comment.