Skip to content

Commit aa4608d

Browse files
author
Oren Novotny
committed
Address #609 by comparing generated text to existing text
1 parent c894b3d commit aa4608d

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/GitVersionTask/AssemblyInfoBuilder/UpdateAssemblyInfo.cs

Lines changed: 19 additions & 1 deletion
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;
@@ -95,7 +96,24 @@ void CreateTempAssemblyInfo(VersionVariables versionVariables)
9596

9697
var assemblyInfoBuilder = new AssemblyInfoBuilder();
9798
var assemblyInfo = assemblyInfoBuilder.GetAssemblyInfoText(versionVariables, RootNamespace);
98-
File.WriteAllText(AssemblyInfoTempFilePath, assemblyInfo);
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);
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)