File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed
Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,7 @@ private static void DumpUsedReferences(CompilationAnalysisContext context)
9090 }
9191 }
9292
93- File . WriteAllLines ( Path . Combine ( Path . GetDirectoryName ( declaredReferencesPath ) , UsedReferencesFileName ) , usedReferences ) ;
93+ WriteUsedReferencesToFile ( usedReferences , declaredReferencesPath ) ;
9494
9595 Dictionary < string , List < string > > packageAssembliesDict = new ( StringComparer . OrdinalIgnoreCase ) ;
9696 foreach ( DeclaredReference declaredReference in declaredReferences . References )
@@ -141,6 +141,30 @@ private static void DumpUsedReferences(CompilationAnalysisContext context)
141141 }
142142 }
143143
144+ private static void WriteUsedReferencesToFile ( HashSet < string > usedReferences , string declaredReferencesPath )
145+ {
146+ string filePath = Path . Combine ( Path . GetDirectoryName ( declaredReferencesPath ) , UsedReferencesFileName ) ;
147+
148+ string text = string . Join ( Environment . NewLine , usedReferences . OrderBy ( s => s ) ) ;
149+
150+ try
151+ {
152+ if ( File . Exists ( filePath ) )
153+ {
154+ string oldText = File . ReadAllText ( filePath ) ;
155+ if ( string . Equals ( text , oldText , StringComparison . OrdinalIgnoreCase ) )
156+ {
157+ return ;
158+ }
159+ }
160+
161+ File . WriteAllText ( filePath , text ) ;
162+ }
163+ catch
164+ {
165+ }
166+ }
167+
144168 private static string ? GetDeclaredReferencesPath ( CompilationAnalysisContext context )
145169 {
146170 foreach ( AdditionalText additionalText in context . Options . AdditionalFiles )
You can’t perform that action at this time.
0 commit comments