PowerShellGetv2 icon indicating copy to clipboard operation
PowerShellGetv2 copied to clipboard

Publish-Module breaks if $OFS is set to anything but " "

Open ghost opened this issue 4 years ago • 4 comments

Steps to reproduce

$OFS = ", "
Publish-Module -Name Example -Repository SomeRepo

Expected behavior

Module published.

Actual behavior

Failed to generate the compressed file for module 'C:\Tools\nuget.exe failed to pack: error Unknown command: 'pack,'
'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2\PSModule.psm1:10945 char:17
+ ...             Publish-PSArtifactUtility @PublishPSArtifactUtility_Param ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : FailedToCreateCompressedModule,Publish-PSArtifactUtility

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.18362.145
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0, 5.0, 5.1.18362.145}
BuildVersion                   10.0.18362.145
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
> Get-Module -ListAvailable PowerShellGet,PackageManagement
    Directory: C:\Users\me\Documents\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.4.3      PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...
Script     2.2        PowerShellGet                       {Find-Command, Find-DSCResource, Find-Module, Find-RoleCap...


    Directory: C:\Program Files\WindowsPowerShell\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.4.3      PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...
Script     1.4.2      PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...
Binary     1.0.0.1    PackageManagement                   {Find-Package, Get-Package, Get-PackageProvider, Get-Packa...
Script     2.2        PowerShellGet                       {Find-Command, Find-DSCResource, Find-Module, Find-RoleCap...
Script     1.0.0.1    PowerShellGet                       {Install-Module, Find-Module, Save-Module, Update-Module, ...
> Get-PackageProvider -ListAvailable
Name                     Version          DynamicOptions
----                     -------          --------------
msi                      3.0.0.0          AdditionalArguments
msu                      3.0.0.0
nuget                    2.8.5.208
NuGet                    3.0.0.1          Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag...
PowerShellGet            2.2.0.0          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, ...
PowerShellGet            1.0.0.1
Programs                 3.0.0.0          IncludeWindowsInstaller, IncludeSystemComponent
> nuget help
NuGet Version: 5.1.0.6013

Additional information

My debugging attempts tracked the issue down to this line in New-NugetPackage:

$processStartInfo.Arguments = $ArgumentList

This casts an array ($ArgumentList) to a string, assuming that it will be joined with spaces. This is only true if $OFS is set to " ", which, while currently the default, is not guaranteed.

This bug exists in other functions called during the publishing process, but New-NugetPackage is the first one to trigger it.

Proposed solution

One of:

  1. Explicitly join the array with spaces using -join.
  2. Don't generate an array at all, and directly set $processStartInfo.Arguments to a string with appropriate interpolations.

ghost avatar Aug 22 '19 19:08 ghost

@alexbuzzbee thanks for reporting this bug, and taking the time to do some de-bugging...both of your proposed solutions seem valid, although we are undertaking a major re-work of PowerShellGet right now so I cannot promise we will have bandwidth to address this in the near future (although we do accept PRs 😄 )...thanks!

SydneyhSmith avatar Aug 22 '19 22:08 SydneyhSmith

... although we are undertaking a major re-work of PowerShellGet right now ...

@SydneyhSmith can you please provide more information on this?

marckassay avatar Nov 13 '19 14:11 marckassay

Yes--the RFC is here: https://github.com/PowerShell/PowerShell-RFC/pull/185 We are targeting a public preview for this module by the end of this year.

SydneyhSmith avatar Nov 14 '19 23:11 SydneyhSmith

@SydneyhSmith Ok, thank you!

marckassay avatar Nov 15 '19 20:11 marckassay