Skip to content

Commit 29f2362

Browse files
committed
Merge pull request #610 from onovotny/fix-rebuilds
Address #609 by comparing generated text to existing text
2 parents c894b3d + 050847b commit 29f2362

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
using System;
44
using System.IO;
5+
using System.Text;
56
using GitVersion;
67
using GitVersion.Helpers;
78
using Microsoft.Build.Framework;
@@ -94,8 +95,25 @@ void CreateTempAssemblyInfo(VersionVariables versionVariables)
9495
}
9596

9697
var assemblyInfoBuilder = new AssemblyInfoBuilder();
97-
var assemblyInfo = assemblyInfoBuilder.GetAssemblyInfoText(versionVariables, RootNamespace);
98-
File.WriteAllText(AssemblyInfoTempFilePath, assemblyInfo);
98+
var assemblyInfo = assemblyInfoBuilder.GetAssemblyInfoText(versionVariables, RootNamespace).Trim();
99+
100+
// We need to try to read the existing text first if the file exists and see if it's the same
101+
// This is to avoid writing when there's no differences and causing a rebuild
102+
try
103+
{
104+
if (File.Exists(AssemblyInfoTempFilePath))
105+
{
106+
var content = File.ReadAllText(AssemblyInfoTempFilePath, Encoding.UTF8).Trim();
107+
if (string.Equals(assemblyInfo, content, StringComparison.Ordinal))
108+
return; // nothign to do as the file matches what we'd create
109+
}
110+
}
111+
catch (Exception)
112+
{
113+
// Something happened reading the file, try to overwrite anyway
114+
}
115+
116+
File.WriteAllText(AssemblyInfoTempFilePath, assemblyInfo, Encoding.UTF8);
99117
}
100118
}
101119
}

0 commit comments

Comments
 (0)