File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
src/GitVersionTask/AssemblyInfoBuilder Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 2
2
{
3
3
using System ;
4
4
using System . IO ;
5
+ using System . Text ;
5
6
using GitVersion ;
6
7
using GitVersion . Helpers ;
7
8
using Microsoft . Build . Framework ;
@@ -94,8 +95,25 @@ void CreateTempAssemblyInfo(VersionVariables versionVariables)
94
95
}
95
96
96
97
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 ) ;
99
117
}
100
118
}
101
119
}
You can’t perform that action at this time.
0 commit comments