diff --git a/src/code/Utils.cs b/src/code/Utils.cs index 89de7cd10..479f3b075 100644 --- a/src/code/Utils.cs +++ b/src/code/Utils.cs @@ -1196,24 +1196,24 @@ internal static void GetMetadataFilesFromPath(string dirPath, string packageName if (string.Compare($"{packageName}.psd1", fileName, StringComparison.OrdinalIgnoreCase) == 0) { properCasingPkgName = Path.GetFileNameWithoutExtension(file); + psd1FilePath = file; } - psd1FilePath = file; } else if (file.EndsWith("nuspec")) { if (string.Compare($"{packageName}.nuspec", fileName, StringComparison.OrdinalIgnoreCase) == 0) { properCasingPkgName = Path.GetFileNameWithoutExtension(file); + nuspecFilePath = file; } - nuspecFilePath = file; } else if (file.EndsWith("ps1")) { if (string.Compare($"{packageName}.ps1", fileName, StringComparison.OrdinalIgnoreCase) == 0) { properCasingPkgName = Path.GetFileNameWithoutExtension(file); + ps1FilePath = file; } - ps1FilePath = file; } } } diff --git a/test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1 b/test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1 index b89a245ee..5ea53bde9 100644 --- a/test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1 +++ b/test/FindPSResourceTests/FindPSResourceLocal.Tests.ps1 @@ -338,4 +338,15 @@ Describe 'Test Find-PSResource for local repositories' -tags 'CI' { $res.Version | Should -Be $nupkgVersion $res.Prerelease | Should -Be $prereleaseLabel } + + It "find module that has multiple manifests and use exact name match one" { + # Az.KeyVault has 2 manifest files - Az.KeyVault.psd1 and Az.KeyVault.Extension.psd1 + # this test was added because PSResourceGet would previously pick the .psd1 file by pattern matching the module name, not exact matching it + # this meant Az.KeyVault.Extension.psd1 and its metadata was being returned. + # The package is present on PSGallery but issue reproduces when looking at the package's file paths in local repo + $PSGalleryName = Get-PSGalleryName + Save-PSResource -Name 'Az.KeyVault' -Version '6.3.1' -Repository $PSGalleryName -AsNupkg -Path $localRepoUriAddress -TrustRepository + $res = Find-PSResource -Name 'Az.KeyVault' -Repository $localRepo + $res.Version | Should -Be "6.3.1" + } }