@@ -138,7 +138,7 @@ public HashSet<AssemblyLookupLocation> Restore()
138138 compilationInfoContainer . CompilationInfos . Add ( ( "Inherited NuGet feed count" , inheritedFeeds . Count . ToString ( ) ) ) ;
139139 }
140140
141- if ( ! CheckSpecifiedFeeds ( explicitFeeds , out var reachableFeeds ) )
141+ if ( ! CheckSpecifiedFeeds ( explicitFeeds ) )
142142 {
143143 // 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.
144144 var unresponsiveMissingPackageLocation = DownloadMissingPackagesFromSpecificFeeds ( [ ] , explicitFeeds ) ;
@@ -147,6 +147,9 @@ public HashSet<AssemblyLookupLocation> Restore()
147147 : [ unresponsiveMissingPackageLocation ] ;
148148 }
149149
150+ // All explicit feeds can be considered reachable
151+ HashSet < string > reachableFeeds = [ ] ;
152+ reachableFeeds . UnionWith ( explicitFeeds ) ;
150153 reachableFeeds . UnionWith ( GetReachableNuGetFeeds ( inheritedFeeds , isFallback : false ) ) ;
151154
152155 // If feed responsiveness is being checked, we only want to use the feeds that are reachable (note this set includes private
@@ -231,15 +234,15 @@ public HashSet<AssemblyLookupLocation> Restore()
231234 /// <param name="feedsToCheck">The feeds to check.</param>
232235 /// <param name="isFallback">Whether the feeds are fallback feeds or not.</param>
233236 /// <returns>The list of feeds that could be reached.</returns>
234- private HashSet < string > GetReachableNuGetFeeds ( HashSet < string > feedsToCheck , bool isFallback )
237+ private List < string > GetReachableNuGetFeeds ( HashSet < string > feedsToCheck , bool isFallback )
235238 {
236239 var fallbackStr = isFallback ? "fallback " : "" ;
237240 logger . LogInfo ( $ "Checking { fallbackStr } NuGet feed reachability on feeds: { string . Join ( ", " , feedsToCheck . OrderBy ( f => f ) ) } ") ;
238241
239242 var ( initialTimeout , tryCount ) = GetFeedRequestSettings ( isFallback ) ;
240243 var reachableFeeds = feedsToCheck
241244 . Where ( feed => IsFeedReachable ( feed , initialTimeout , tryCount , allowExceptions : false ) )
242- . ToHashSet ( ) ;
245+ . ToList ( ) ;
243246
244247 if ( reachableFeeds . Count == 0 )
245248 {
@@ -253,7 +256,7 @@ private HashSet<string> GetReachableNuGetFeeds(HashSet<string> feedsToCheck, boo
253256 return reachableFeeds ;
254257 }
255258
256- private HashSet < string > GetReachableFallbackNugetFeeds ( HashSet < string > ? feedsFromNugetConfigs )
259+ private List < string > GetReachableFallbackNugetFeeds ( HashSet < string > ? feedsFromNugetConfigs )
257260 {
258261 var fallbackFeeds = EnvironmentVariables . GetURLs ( EnvironmentVariableNames . FallbackNugetFeeds ) . ToHashSet ( ) ;
259262 if ( fallbackFeeds . Count == 0 )
@@ -775,37 +778,29 @@ private HashSet<string> GetExcludedFeeds()
775778 /// </summary>
776779 /// <param name="feeds">The set of package feeds to check.</param>
777780 /// <returns>
778- /// True if all feeds are reachable or false otherwise.
779- /// Also returns the set of reachable feeds as an out parameter.
781+ /// True if all feeds are reachable (excluding any feeds that are configured to be excluded from the check) or false otherwise.
780782 /// </returns>
781- private bool CheckSpecifiedFeeds ( HashSet < string > feeds , out HashSet < string > reachableFeeds )
783+ private bool CheckSpecifiedFeeds ( HashSet < string > feeds )
782784 {
783785 // Exclude any feeds from the feed check that are configured by the corresponding environment variable.
784786 // These feeds are always assumed to be reachable.
785787 var excludedFeeds = GetExcludedFeeds ( ) ;
786788
787- HashSet < string > feedsToCheck = [ ] ;
788- HashSet < string > feedsNotToCheck = [ ] ;
789- foreach ( var feed in feeds )
789+ HashSet < string > feedsToCheck = feeds . Where ( feed =>
790790 {
791791 if ( excludedFeeds . Contains ( feed ) )
792792 {
793793 logger . LogInfo ( $ "Not checking reachability of NuGet feed '{ feed } ' as it is in the list of excluded feeds.") ;
794- feedsNotToCheck . Add ( feed ) ;
795- }
796- else
797- {
798- feedsToCheck . Add ( feed ) ;
794+ return false ;
799795 }
800- }
796+ return true ;
797+ } ) . ToHashSet ( ) ;
801798
802- reachableFeeds = GetReachableNuGetFeeds ( feedsToCheck , isFallback : false ) ;
799+ var reachableFeeds = GetReachableNuGetFeeds ( feedsToCheck , isFallback : false ) ;
803800 var allFeedsReachable = reachableFeeds . Count == feedsToCheck . Count ;
804801
805802 EmitUnreachableFeedsDiagnostics ( allFeedsReachable ) ;
806803
807- reachableFeeds . UnionWith ( feedsNotToCheck ) ;
808-
809804 return allFeedsReachable ;
810805 }
811806
0 commit comments