@@ -387,29 +387,45 @@ private FindResults FindVersionHelper(string packageName, string version, string
387387 return findResponse ;
388388 }
389389
390- WildcardPattern pkgNamePattern = new WildcardPattern ( $ "{ packageName } .*", WildcardOptions . IgnoreCase ) ;
390+ string regexPattern = $ "{ packageName } .{ requiredVersion . ToNormalizedString ( ) } " + @".nupkg" ;
391+ Regex rx = new Regex ( regexPattern , RegexOptions . Compiled | RegexOptions . IgnoreCase ) ;
392+ _cmdletPassedIn . WriteDebug ( $ "pattern is: { regexPattern } ") ;
391393 string pkgPath = String . Empty ;
392394 string actualPkgName = String . Empty ;
395+
393396 foreach ( string path in Directory . GetFiles ( Repository . Uri . LocalPath ) )
394397 {
395398 string packageFullName = Path . GetFileName ( path ) ;
396- if ( ! String . IsNullOrEmpty ( packageFullName ) && pkgNamePattern . IsMatch ( packageFullName ) )
399+ MatchCollection matches = rx . Matches ( packageFullName ) ;
400+ if ( matches . Count == 0 )
397401 {
398- NuGetVersion nugetVersion = GetInfoFromFileName ( packageFullName : packageFullName , packageName : packageName , actualName : out actualPkgName , out errRecord ) ;
399- _cmdletPassedIn . WriteDebug ( $ "' { packageName } ' version parsed as ' { nugetVersion } '" ) ;
402+ continue ;
403+ }
400404
401- if ( errRecord != null )
402- {
403- return findResponse ;
404- }
405+ Match match = matches [ 0 ] ;
405406
406- if ( nugetVersion == requiredVersion )
407- {
408- _cmdletPassedIn . WriteDebug ( "Found matching version" ) ;
409- string pkgFullName = $ "{ actualPkgName } .{ nugetVersion . ToString ( ) } .nupkg";
410- pkgPath = Path . Combine ( Repository . Uri . LocalPath , pkgFullName ) ;
411- break ;
412- }
407+ GroupCollection groups = match . Groups ;
408+ if ( groups . Count == 0 )
409+ {
410+ continue ;
411+ }
412+
413+ Capture group = groups [ 0 ] ;
414+
415+ NuGetVersion nugetVersion = GetInfoFromFileName ( packageFullName : packageFullName , packageName : packageName , actualName : out actualPkgName , out errRecord ) ;
416+ _cmdletPassedIn . WriteDebug ( $ "Version parsed as '{ nugetVersion } '") ;
417+
418+ if ( errRecord != null )
419+ {
420+ return findResponse ;
421+ }
422+
423+ if ( nugetVersion == requiredVersion )
424+ {
425+ _cmdletPassedIn . WriteDebug ( "Found matching version" ) ;
426+ string pkgFullName = $ "{ actualPkgName } .{ nugetVersion . ToString ( ) } .nupkg";
427+ pkgPath = Path . Combine ( Repository . Uri . LocalPath , pkgFullName ) ;
428+ break ;
413429 }
414430 }
415431
0 commit comments