@@ -109,7 +109,7 @@ public HashSet<AssemblyLookupLocation> Restore()
109
109
if ( checkNugetFeedResponsiveness && ! CheckFeeds ( out explicitFeeds ) )
110
110
{
111
111
// todo: we could also check the reachability of the inherited nuget feeds, but to use those in the fallback we would need to handle authentication too.
112
- var unresponsiveMissingPackageLocation = DownloadMissingPackagesFromSpecificFeeds ( explicitFeeds ) ;
112
+ var unresponsiveMissingPackageLocation = DownloadMissingPackagesFromSpecificFeeds ( [ ] , explicitFeeds ) ;
113
113
return unresponsiveMissingPackageLocation is null
114
114
? [ ]
115
115
: [ unresponsiveMissingPackageLocation ] ;
@@ -166,11 +166,11 @@ public HashSet<AssemblyLookupLocation> Restore()
166
166
. ToList ( ) ;
167
167
assemblyLookupLocations . UnionWith ( paths . Select ( p => new AssemblyLookupLocation ( p ) ) ) ;
168
168
169
- LogAllUnusedPackages ( dependencies ) ;
169
+ var usedPackageNames = GetAllUsedPackageDirNames ( dependencies ) ;
170
170
171
171
var missingPackageLocation = checkNugetFeedResponsiveness
172
- ? DownloadMissingPackagesFromSpecificFeeds ( explicitFeeds )
173
- : DownloadMissingPackages ( ) ;
172
+ ? DownloadMissingPackagesFromSpecificFeeds ( usedPackageNames , explicitFeeds )
173
+ : DownloadMissingPackages ( usedPackageNames ) ;
174
174
175
175
if ( missingPackageLocation is not null )
176
176
{
@@ -297,21 +297,21 @@ private void RestoreProjects(IEnumerable<string> projects, out ConcurrentBag<Dep
297
297
compilationInfoContainer . CompilationInfos . Add ( ( "Failed project restore with package source error" , nugetSourceFailures . ToString ( ) ) ) ;
298
298
}
299
299
300
- private AssemblyLookupLocation ? DownloadMissingPackagesFromSpecificFeeds ( HashSet < string > ? feedsFromNugetConfigs )
300
+ private AssemblyLookupLocation ? DownloadMissingPackagesFromSpecificFeeds ( IEnumerable < string > usedPackageNames , HashSet < string > ? feedsFromNugetConfigs )
301
301
{
302
302
var reachableFallbackFeeds = GetReachableFallbackNugetFeeds ( feedsFromNugetConfigs ) ;
303
303
if ( reachableFallbackFeeds . Count > 0 )
304
304
{
305
- return DownloadMissingPackages ( fallbackNugetFeeds : reachableFallbackFeeds ) ;
305
+ return DownloadMissingPackages ( usedPackageNames , fallbackNugetFeeds : reachableFallbackFeeds ) ;
306
306
}
307
307
308
308
logger . LogWarning ( "Skipping download of missing packages from specific feeds as no fallback Nuget feeds are reachable." ) ;
309
309
return null ;
310
310
}
311
311
312
- private AssemblyLookupLocation ? DownloadMissingPackages ( IEnumerable < string > ? fallbackNugetFeeds = null )
312
+ private AssemblyLookupLocation ? DownloadMissingPackages ( IEnumerable < string > usedPackageNames , IEnumerable < string > ? fallbackNugetFeeds = null )
313
313
{
314
- var alreadyDownloadedPackages = GetRestoredPackageDirectoryNames ( PackageDirectory . DirInfo ) ;
314
+ var alreadyDownloadedPackages = usedPackageNames . Select ( p => p . ToLowerInvariant ( ) ) ;
315
315
var alreadyDownloadedLegacyPackages = GetRestoredLegacyPackageNames ( ) ;
316
316
317
317
var notYetDownloadedPackages = new HashSet < PackageReference > ( fileContent . AllPackages ) ;
@@ -418,17 +418,23 @@ private void RestoreProjects(IEnumerable<string> projects, out ConcurrentBag<Dep
418
418
return nugetConfig ;
419
419
}
420
420
421
- private void LogAllUnusedPackages ( DependencyContainer dependencies )
421
+ private IEnumerable < string > GetAllUsedPackageDirNames ( DependencyContainer dependencies )
422
422
{
423
423
var allPackageDirectories = GetAllPackageDirectories ( ) ;
424
424
425
425
logger . LogInfo ( $ "Restored { allPackageDirectories . Count } packages") ;
426
426
logger . LogInfo ( $ "Found { dependencies . Packages . Count } packages in project.assets.json files") ;
427
427
428
- allPackageDirectories
429
- . Where ( package => ! dependencies . Packages . Contains ( package ) )
428
+ var usage = allPackageDirectories . Select ( package => ( package , isUsed : dependencies . Packages . Contains ( package ) ) ) ;
429
+
430
+ usage
431
+ . Where ( package => ! package . isUsed )
430
432
. Order ( )
431
- . ForEach ( package => logger . LogDebug ( $ "Unused package: { package } ") ) ;
433
+ . ForEach ( package => logger . LogDebug ( $ "Unused package: { package . package } ") ) ;
434
+
435
+ return usage
436
+ . Where ( package => package . isUsed )
437
+ . Select ( package => package . package ) ;
432
438
}
433
439
434
440
private ICollection < string > GetAllPackageDirectories ( )
0 commit comments