@@ -106,9 +106,7 @@ where string.Equals(item.GetMetadata("Generator"), $"MSBuild:{this.TargetName}",
106106 string outputFilePath = Path . Combine ( this . IntermediateOutputDirectory , Path . GetFileNameWithoutExtension ( inputSyntaxTree . FilePath ) + $ ".{ sourceHash } .generated.cs") ;
107107
108108 // Code generation is relatively fast, but it's not free.
109- // And when we run the Simplifier.ReduceAsync it's dog slow.
110109 // So skip files that haven't changed since we last generated them.
111- bool generated = false ;
112110 DateTime outputLastModified = File . Exists ( outputFilePath ) ? File . GetLastWriteTime ( outputFilePath ) : DateTime . MinValue ;
113111 if ( File . GetLastWriteTime ( inputSyntaxTree . FilePath ) > outputLastModified || assembliesLastModified > outputLastModified )
114112 {
@@ -117,39 +115,30 @@ where string.Equals(item.GetMetadata("Generator"), $"MSBuild:{this.TargetName}",
117115 inputSyntaxTree ,
118116 new ProgressLogger ( this . Log , inputSyntaxTree . FilePath ) ) ;
119117
120- // Only produce a new file if the generated document has generated a type.
121- bool anyMembersGenerated = generatedSyntaxTree ? . GetRoot ( this . CancellationToken ) . DescendantNodes ( ) . OfType < TypeDeclarationSyntax > ( ) . Any ( ) ?? false ;
122- if ( anyMembersGenerated )
118+ var outputText = generatedSyntaxTree . GetText ( this . CancellationToken ) ;
119+ using ( var outputFileStream = File . OpenWrite ( outputFilePath ) )
120+ using ( var outputWriter = new StreamWriter ( outputFileStream ) )
123121 {
124- var outputText = generatedSyntaxTree . GetText ( this . CancellationToken ) ;
125- using ( var outputFileStream = File . OpenWrite ( outputFilePath ) )
126- using ( var outputWriter = new StreamWriter ( outputFileStream ) )
127- {
128- outputText . Write ( outputWriter ) ;
122+ outputText . Write ( outputWriter ) ;
129123
130- // Truncate any data that may be beyond this point if the file existed previously.
131- outputWriter . Flush ( ) ;
132- outputFileStream . SetLength ( outputFileStream . Position ) ;
133- }
124+ // Truncate any data that may be beyond this point if the file existed previously.
125+ outputWriter . Flush ( ) ;
126+ outputFileStream . SetLength ( outputFileStream . Position ) ;
127+ }
134128
129+ bool anyTypesGenerated = generatedSyntaxTree ? . GetRoot ( this . CancellationToken ) . DescendantNodes ( ) . OfType < TypeDeclarationSyntax > ( ) . Any ( ) ?? false ;
130+ if ( anyTypesGenerated )
131+ {
135132 this . Log . LogMessage ( MessageImportance . Normal , "{0} -> {1}" , inputSyntaxTree . FilePath , outputFilePath ) ;
136- generated = true ;
137133 }
138134 else
139135 {
140136 this . Log . LogMessage ( MessageImportance . Low , "{0} used no code generation attributes." , inputSyntaxTree . FilePath ) ;
141137 }
142138 }
143- else
144- {
145- generated = true ;
146- }
147139
148- if ( generated )
149- {
150- var outputItem = new TaskItem ( outputFilePath ) ;
151- outputFiles . Add ( outputItem ) ;
152- }
140+ var outputItem = new TaskItem ( outputFilePath ) ;
141+ outputFiles . Add ( outputItem ) ;
153142 }
154143
155144 this . SaveGeneratorAssemblyList ( generatorAssemblyInputsFile ) ;
0 commit comments