PowerShell / PowerShellGetv2

PowerShellGet is the Package Manager for PowerShell
https://www.PowerShellGallery.com
MIT License
431 stars 138 forks source link

Publish-Module does not work if RequiredModules has $PSScriptRoot in module path #198

Closed bergmeister closed 6 years ago

bergmeister commented 6 years ago

I am trying to publish a module that declares a dependency on another module in the manifest and this dependency gets shipped as part of the module in the same working directory. I declare it as:

RequiredModules = @("$PSScriptRoot\vsts-cli-tabcompletion.psd1")

Publish-Module would only allow me to upload the module if I replaced $PSScriptRoot with .\so that it becomes RequiredModules = @(".\vsts-cli-tabcompletion.psd1") but when someone installs this module then, they would get an error when importing since they would be in a different working directory.

Expected Behavior

Module uploads without errors.

Current Behavior

Publish-Module returns an error:

Publish-PSArtifactUtility : Failed to publish module 'posh-vsts-cli': 'Failed to process request. 'There were errors
extracting PowerShell metadata: Unexpected element encountered: ""$PSScriptRoot\vsts-cli-tabcompletion.psd1"". Line
numbers: 54-54.'.
The remote server returned an error: (500) Internal Server Error..
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1227 char:17
+                 Publish-PSArtifactUtility -PSModuleInfo $moduleInfo `
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : FailedToPublishTheModule,Publish-PSArtifactUtility

Your Environment


> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.16299.64
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.16299.64
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

> Get-Module

> Get-Module -ListAvailable PowerShellGet,PackageManagement
ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.1.7.0    PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...}
Binary     1.0.0.1    PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-PackageSource...}
Script     1.0.0.1    PowerShellGet                       {Install-Module, Find-Module, Save-Module, Update-Module...}

> Get-PackageProvider
Name                     Version          DynamicOptions
----                     -------          --------------
msi                      3.0.0.0          AdditionalArguments
msu                      3.0.0.0
NuGet                    2.8.5.210        Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, Contains, AllowPrereleaseVersions, ConfigFile, SkipValidate
PowerShellGet            1.0.0.1          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, InstallUpdate, NoPathUpdate, Filter, Tag, Includes, DscResource...
Programs                 3.0.0.0          IncludeWindowsInstaller, IncludeSystemComponent
> Get-PackageProvider -ListAvailable
Name                     Version          DynamicOptions
----                     -------          --------------
msi                      3.0.0.0          AdditionalArguments
msu                      3.0.0.0
nuget                    2.8.5.208
NuGet                    2.8.5.210        Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, Contains, AllowPrereleaseVersions, ConfigFile, SkipValidate
PowerShellGet            1.0.0.1          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, InstallUpdate, NoPathUpdate, Filter, Tag, Includes, DscResource...
Programs                 3.0.0.0          IncludeWindowsInstaller, IncludeSystemComponent
bergmeister commented 6 years ago

Note that I could resolve my issue by using NestedModules instead where the relative path .\ to the dependent module worked. Maybe this is by design but I found the documentation to be not very helpful/intuitive.

bmanikm commented 6 years ago

Since the dependency is part of the module folder, it is needs to be listed as part of the NestedModules entry. New-ModuleManifest cmdlet documentation can be found here.

bergmeister commented 6 years ago

thanks