@@ -32,6 +32,8 @@ public NuGetDiffCommand()
3232
3333 public bool PrePrelease { get ; set ; }
3434
35+ public bool IgnoreUnchanged { get ; set ; }
36+
3537 public string OutputDirectory { get ; set ; }
3638
3739 protected override OptionSet OnCreateOptions ( ) => new OptionSet
@@ -42,6 +44,7 @@ public NuGetDiffCommand()
4244 { "latest" , "Compare against the latest" , v => Latest = true } ,
4345 { "output=" , "The output directory" , v => OutputDirectory = v } ,
4446 { "prerelease" , "Include preprelease packages" , v => PrePrelease = true } ,
47+ { "ignore-unchanged" , "Ignore unchanged packages and assemblies" , v => IgnoreUnchanged = true } ,
4548 { "search-path=" , "A search path directory" , v => SearchPaths . Add ( v ) } ,
4649 { "version=" , "The version of the package to compare" , v => Version = v } ,
4750 } ;
@@ -187,9 +190,10 @@ private async Task DiffPackage(NuGetDiff comparer, PackageArchiveReader reader,
187190 Console . WriteLine ( $ "Running a diff on '{ currentVersionNo } ' vs '{ olderVersion } ' of '{ packageId } '...") ;
188191
189192 // run the diff with all changes
190- comparer . SaveAssemblyApiInfo = true ; // we don't keep this, but it lets us know if there were no changes
191- comparer . SaveAssemblyMarkdownDiff = true ; // we want markdown
192- comparer . IgnoreResolutionErrors = true ; // we don't care if frameowrk/platform types can't be found
193+ comparer . SaveNuGetXmlDiff = false ; // this is not needed for this type of diff
194+ comparer . SaveAssemblyApiInfo = ! IgnoreUnchanged ; // this lets us know if there were no changes
195+ comparer . SaveAssemblyMarkdownDiff = true ; // we want markdown
196+ comparer . IgnoreResolutionErrors = true ; // we don't care if frameowrk/platform types can't be found
193197 comparer . MarkdownDiffFileExtension = ".diff.md" ;
194198 comparer . IgnoreNonBreakingChanges = false ;
195199 await comparer . SaveCompleteDiffToDirectoryAsync ( olderReader , reader , diffRoot ) ;
@@ -199,41 +203,44 @@ private async Task DiffPackage(NuGetDiff comparer, PackageArchiveReader reader,
199203 comparer . IgnoreNonBreakingChanges = true ;
200204 await comparer . SaveCompleteDiffToDirectoryAsync ( olderReader , reader , diffRoot ) ;
201205
202- // TODO: there are two bugs in this version of mono-api-html
203- var mdFiles = Directory . EnumerateFiles ( diffRoot , "*.md" , SearchOption . AllDirectories ) ;
204- foreach ( var md in mdFiles )
206+ if ( Directory . Exists ( diffRoot ) )
205207 {
206- var contents = await File . ReadAllTextAsync ( md ) ;
208+ // TODO: there are two bugs in this version of mono-api-html
209+ var mdFiles = Directory . EnumerateFiles ( diffRoot , "*.md" , SearchOption . AllDirectories ) ;
210+ foreach ( var md in mdFiles )
211+ {
212+ var contents = await File . ReadAllTextAsync ( md ) ;
207213
208- // 1. the <h4> doesn't look pretty in the markdown
209- contents = contents . Replace ( "<h4>" , "> " ) ;
210- contents = contents . Replace ( "</h4>" , Environment . NewLine ) ;
214+ // 1. the <h4> doesn't look pretty in the markdown
215+ contents = contents . Replace ( "<h4>" , "> " ) ;
216+ contents = contents . Replace ( "</h4>" , Environment . NewLine ) ;
211217
212- // 2. newlines are inccorrect on Windows: https://github.com/mono/mono/pull/9918
213- contents = contents . Replace ( "\r \r " , "\r " ) ;
218+ // 2. newlines are inccorrect on Windows: https://github.com/mono/mono/pull/9918
219+ contents = contents . Replace ( "\r \r " , "\r " ) ;
214220
215- await File . WriteAllTextAsync ( md , contents ) ;
216- }
221+ await File . WriteAllTextAsync ( md , contents ) ;
222+ }
217223
218- // clean up the changes
219- var xmlFiles = Directory . EnumerateFiles ( diffRoot , "*.xml" , SearchOption . AllDirectories ) ;
220- foreach ( var file in xmlFiles )
221- {
222- // make sure to create markdown files for unchanged assemblies
223- if ( file . EndsWith ( ".new.info.xml" , StringComparison . OrdinalIgnoreCase ) )
224+ // clean up the changes
225+ var xmlFiles = Directory . EnumerateFiles ( diffRoot , "*.xml" , SearchOption . AllDirectories ) ;
226+ foreach ( var file in xmlFiles )
224227 {
225- var dll = Path . GetFileNameWithoutExtension ( Path . GetFileNameWithoutExtension ( Path . GetFileNameWithoutExtension ( file ) ) ) ;
226- var md = $ "{ Path . GetDirectoryName ( file ) } /{ dll } .diff.md";
227- if ( ! File . Exists ( md ) )
228+ // make sure to create markdown files for unchanged assemblies
229+ if ( file . EndsWith ( ".new.info.xml" , StringComparison . OrdinalIgnoreCase ) )
228230 {
229- var n = Environment . NewLine ;
230- var noChangesText = $ "# API diff: { dll } { n } { n } ## { dll } { n } { n } > No changes.{ n } ";
231- await File . WriteAllTextAsync ( md , noChangesText ) ;
231+ var dll = Path . GetFileNameWithoutExtension ( Path . GetFileNameWithoutExtension ( Path . GetFileNameWithoutExtension ( file ) ) ) ;
232+ var md = $ "{ Path . GetDirectoryName ( file ) } /{ dll } .diff.md";
233+ if ( ! File . Exists ( md ) )
234+ {
235+ var n = Environment . NewLine ;
236+ var noChangesText = $ "# API diff: { dll } { n } { n } ## { dll } { n } { n } > No changes.{ n } ";
237+ await File . WriteAllTextAsync ( md , noChangesText ) ;
238+ }
232239 }
233- }
234240
235- // delete the info files now
236- File . Delete ( file ) ;
241+ // delete the info files now
242+ File . Delete ( file ) ;
243+ }
237244 }
238245
239246 // we are done
0 commit comments