diff --git a/src/code/PublishPSResource.cs b/src/code/PublishPSResource.cs index eaa6b3942..27f1005aa 100644 --- a/src/code/PublishPSResource.cs +++ b/src/code/PublishPSResource.cs @@ -725,7 +725,6 @@ private Hashtable ParseRequiredModules(Hashtable parsedMetadataHash) { return null; } - var requiredModules = parsedMetadataHash["requiredmodules"]; // Required modules can be: @@ -752,6 +751,20 @@ private Hashtable ParseRequiredModules(Hashtable parsedMetadataHash) } } + var externalModuleDeps = parsedMetadataHash.ContainsKey("ExternalModuleDependencies") ? + parsedMetadataHash["ExternalModuleDependencies"] : null; + + if (externalModuleDeps != null && LanguagePrimitives.TryConvertTo(externalModuleDeps, out string[] externalModuleNames)) + { + foreach (var extModName in externalModuleNames) + { + if (dependenciesHash.ContainsKey(extModName)) + { + dependenciesHash.Remove(extModName); + } + } + } + return dependenciesHash; } diff --git a/test/PublishPSResourceTests/PublishPSResource.Tests.ps1 b/test/PublishPSResourceTests/PublishPSResource.Tests.ps1 index 52f22a6cf..afa1b77ab 100644 --- a/test/PublishPSResourceTests/PublishPSResource.Tests.ps1 +++ b/test/PublishPSResourceTests/PublishPSResource.Tests.ps1 @@ -529,6 +529,18 @@ Describe "Test Publish-PSResource" -tags 'CI' { (Get-ChildItem $script:repositoryPath).FullName | Should -Be $expectedPath } + It "should publish a script with sExternalModuleDependencies that are not published" { + $scriptName = "test" + $scriptVersion = "1.0.0" + $scriptPath = Join-Path -Path $script:testScriptsFolderPath -ChildPath "$scriptName.ps1" + New-PSScriptFileInfo -Description 'test' -Version $scriptVersion -RequiredModules @{ModuleName='testModule'} -ExternalModuleDependencies 'testModule' -Path $scriptPath -Force + + Publish-PSResource -Path $scriptPath + + $expectedPath = Join-Path -Path $script:repositoryPath -ChildPath "$scriptName.$scriptVersion.nupkg" + (Get-ChildItem $script:repositoryPath).FullName | Should -Be $expectedPath + } + It "should write error and not publish script when Author property is missing" { $scriptName = "InvalidScriptMissingAuthor.ps1" $scriptVersion = "1.0.0"