-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
This is essentially a duplicate of closed issue 3663 which was marked as closed because while it failed in PowerShell 5.1 as the original poster commented, @SteveL-MSFT, indicated this works in PowerShell 6. I can not get it to work in 6.0.4.
I'm unclear as to why the required modules have to be installed locally before publishing. As part of the publishing process, a check is performed to ensure that the required modules are available on the repo. If the required modules are not available on the repo, the publishing of the module fails. If the required modules are found on the repo, the publishing of the module will succeed. With that workflow, why require them to be installed locally?
Steps to reproduce
New-ModuleManifest m.psd1 -RequiredModules sub
Test-ModuleManifest m.psd1 -verbose
Expected behavior
I'd expect it to return details on the module being tested. For example:
Test-ModuleManifest m.psd1 -Verbose
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 0.0.1 mActual behavior
I get an error
Test-ModuleManifest m.psd1 -Verbose
Test-ModuleManifest : The specified RequiredModules entry 'sub' in the module manifest 'C:\Inbox\m.psd1' is invalid. Try again after updating this entry with valid values.
At line:1 char:1
+ Test-ModuleManifest m.psd1 -Verbose
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (m.psd1:String) [Test-ModuleManifest], DirectoryNotFoundException
+ FullyQualifiedErrorId : Modules_InvalidRequiredModulesinModuleManifest,Microsoft.PowerShell.Commands.TestModuleManifestCommand
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Manifest 0.0.1 m
Environment data
This happens in version 6.0.4 on both Windows and Ubunutu
Windows
> $PSVersionTable
Name Value
---- -----
PSVersion 6.0.4
PSEdition Core
GitCommitId v6.0.4
OS Microsoft Windows 10.0.14393
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0Ubuntu
> $PSVersionTable
Name Value
---- -----
PSVersion 6.0.4
PSEdition Core
GitCommitId v6.0.4
OS Linux 4.4.0-28-generic #47-Ubuntu SMP Fri Jun...
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Workaround
To get around this limitation, we read in the data file information, create an array of the required modules and install each of them.
# Get .psd1 data
$data = Import-PowerShellDataFile .\*.psd1
# Get the RequiredModules
$requiredModules = $data.RequiredModules.ModuleName
if ($requiredModules) {
# Create credentials used to connect to private NuGet feed
Write-Output 'Creating credentials'
$pwd = ConvertTo-SecureString $NuGetApiKey -AsPlainText -Force
$cred = New-Object Management.Automation.PSCredential ("username", $pwd)
# Install the required modules
foreach ($module in $requiredModules) {
Install-Module $module -Repository $repo -Credential $cred -Verbose
}
}While this works, it adds additional, unneeded overhead.