Skip to content

Commit

Permalink
Merge pull request #610 from onovotny/fix-rebuilds
Browse files Browse the repository at this point in the history
Address #609 by comparing generated text to existing text
  • Loading branch information
JakeGinnivan committed Aug 26, 2015
2 parents c894b3d + 050847b commit 29f2362
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
using System;
using System.IO;
using System.Text;
using GitVersion;
using GitVersion.Helpers;
using Microsoft.Build.Framework;
Expand Down Expand Up @@ -94,8 +95,25 @@ void CreateTempAssemblyInfo(VersionVariables versionVariables)
}

var assemblyInfoBuilder = new AssemblyInfoBuilder();
var assemblyInfo = assemblyInfoBuilder.GetAssemblyInfoText(versionVariables, RootNamespace);
File.WriteAllText(AssemblyInfoTempFilePath, assemblyInfo);
var assemblyInfo = assemblyInfoBuilder.GetAssemblyInfoText(versionVariables, RootNamespace).Trim();

// We need to try to read the existing text first if the file exists and see if it's the same
// This is to avoid writing when there's no differences and causing a rebuild
try
{
if (File.Exists(AssemblyInfoTempFilePath))
{
var content = File.ReadAllText(AssemblyInfoTempFilePath, Encoding.UTF8).Trim();
if (string.Equals(assemblyInfo, content, StringComparison.Ordinal))
return; // nothign to do as the file matches what we'd create
}
}
catch (Exception)
{
// Something happened reading the file, try to overwrite anyway
}

File.WriteAllText(AssemblyInfoTempFilePath, assemblyInfo, Encoding.UTF8);
}
}
}

0 comments on commit 29f2362

Please sign in to comment.