@@ -699,7 +699,7 @@ private IEnumerable<PSResourceInfo> SearchByNames(ServerApiCall currentServer, R
699
699
else
700
700
{
701
701
responses = currentServer . FindNameGlobbingWithTag ( pkgName , _tag , _prerelease , _type , out errRecord ) ;
702
- tagsAsString = String . Join ( ", " , _tag ) ;
702
+ tagsAsString = $ " and tags ' { String . Join ( ", " , _tag ) } '" ;
703
703
}
704
704
705
705
if ( errRecord != null )
@@ -750,7 +750,7 @@ private IEnumerable<PSResourceInfo> SearchByNames(ServerApiCall currentServer, R
750
750
else
751
751
{
752
752
responses = currentServer . FindNameWithTag ( pkgName , _tag , _prerelease , _type , out errRecord ) ;
753
- tagsAsString = String . Join ( ", " , _tag ) ;
753
+ tagsAsString = $ " and tags ' { String . Join ( ", " , _tag ) } '" ;
754
754
}
755
755
756
756
if ( errRecord != null )
@@ -767,7 +767,19 @@ private IEnumerable<PSResourceInfo> SearchByNames(ServerApiCall currentServer, R
767
767
continue ;
768
768
}
769
769
770
- PSResourceResult currentResult = currentResponseUtil . ConvertToPSResourceResult ( responses ) . First ( ) ;
770
+ PSResourceResult currentResult = currentResponseUtil . ConvertToPSResourceResult ( responses ) . FirstOrDefault ( ) ;
771
+ if ( currentResult == null )
772
+ {
773
+ // This scenario may occur when the package version requested is unlisted.
774
+ _cmdletPassedIn . WriteError ( new ErrorRecord (
775
+ new ResourceNotFoundException ( $ "Package with name '{ pkgName } '{ tagsAsString } could not be found in repository '{ repository . Name } '") ,
776
+ "PackageNotFound" ,
777
+ ErrorCategory . ObjectNotFound ,
778
+ this ) ) ;
779
+
780
+ continue ;
781
+ }
782
+
771
783
if ( currentResult . exception != null && ! currentResult . exception . Message . Equals ( string . Empty ) )
772
784
{
773
785
_cmdletPassedIn . WriteError ( new ErrorRecord (
@@ -812,7 +824,7 @@ private IEnumerable<PSResourceInfo> SearchByNames(ServerApiCall currentServer, R
812
824
else
813
825
{
814
826
responses = currentServer . FindVersionWithTag ( pkgName , _nugetVersion . ToNormalizedString ( ) , _tag , _type , out errRecord ) ;
815
- tagsAsString = String . Join ( ", " , _tag ) ;
827
+ tagsAsString = $ " and tags ' { String . Join ( ", " , _tag ) } '" ;
816
828
}
817
829
818
830
if ( errRecord != null )
@@ -829,7 +841,19 @@ private IEnumerable<PSResourceInfo> SearchByNames(ServerApiCall currentServer, R
829
841
continue ;
830
842
}
831
843
832
- PSResourceResult currentResult = currentResponseUtil . ConvertToPSResourceResult ( responses ) . First ( ) ;
844
+ PSResourceResult currentResult = currentResponseUtil . ConvertToPSResourceResult ( responses ) . FirstOrDefault ( ) ;
845
+ if ( currentResult == null )
846
+ {
847
+ // This scenario may occur when the package version requested is unlisted.
848
+ _cmdletPassedIn . WriteError ( new ErrorRecord (
849
+ new ResourceNotFoundException ( $ "Package with name '{ pkgName } ', version '{ _nugetVersion . ToNormalizedString ( ) } '{ tagsAsString } could not be found in repository '{ repository . Name } '") ,
850
+ "PackageNotFound" ,
851
+ ErrorCategory . ObjectNotFound ,
852
+ this ) ) ;
853
+
854
+ continue ;
855
+ }
856
+
833
857
if ( currentResult . exception != null && ! currentResult . exception . Message . Equals ( string . Empty ) )
834
858
{
835
859
_cmdletPassedIn . WriteError ( new ErrorRecord (
@@ -1041,7 +1065,18 @@ internal IEnumerable<PSResourceInfo> FindDependencyPackages(
1041
1065
continue ;
1042
1066
}
1043
1067
1044
- PSResourceResult currentResult = currentResponseUtil . ConvertToPSResourceResult ( responses ) . First ( ) ;
1068
+ PSResourceResult currentResult = currentResponseUtil . ConvertToPSResourceResult ( responses ) . FirstOrDefault ( ) ;
1069
+ if ( currentResult == null )
1070
+ {
1071
+ // This scenario may occur when the package version requested is unlisted.
1072
+ _cmdletPassedIn . WriteError ( new ErrorRecord (
1073
+ new ResourceNotFoundException ( $ "Dependency package with name '{ dep . Name } ' could not be found in repository '{ repository . Name } '") ,
1074
+ "DependencyPackageNotFound" ,
1075
+ ErrorCategory . ObjectNotFound ,
1076
+ this ) ) ;
1077
+ yield return null ;
1078
+ continue ;
1079
+ }
1045
1080
1046
1081
if ( currentResult . exception != null && ! currentResult . exception . Message . Equals ( string . Empty ) )
1047
1082
{
0 commit comments