Skip to content

Address #609 by comparing generated text to existing text #610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 26, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}