PowerShell / PowerShell/PSResourceGet

Publish-Module can't overwrite - nuget can

Aperta
#82 13 commenti 11 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Area-PSRepository
Lingua principale
C#
Stelle
576
Fork
114
Merge medio
1g 2h
PR unite (30g)
7

Descrizione

Expected Behavior

Overwriting modules should be possible - without bumping version number.

Current Behavior

I'm developing PowerShell modules, and I have two nuget repositories, one for snapshots (modules under development) and another one for releases (production ready modules). I'm using Artifactory as an artifact management system, and I've set up both repositories as nuget feeds in there.

First time I publish a module with PowerShellGet, it works. If I run the Publish-Module command again right after, it fails because it won't allow me to overwrite (the user psmodulewriter has permission to overwrite):

PS C:\> Publish-Module -Path 'C:\Workspace\code\UtilsModule' -Repository 'PSSnapshots' -NuGetApiKey 'psmodulewriter:password' -Credential 'psmodulewriter' -Force
PS C:\> Publish-Module -Path 'C:\Workspace\code\UtilsModule' -Repository 'PSSnapshots' -NuGetApiKey 'psmodulewriter:password' -Credential 'psmodulewriter' -Force
Publish-Module : The module 'UtilsModule' with version '0.0.1' cannot be published as the current version '0.0.1' is already available in the repository 'https://xxxx.jfrog.io/xxxxartifactory/api/nuget/xxxxPowerShellRepo-Snapshots/'.
At line:1 char:1
+ Publish-Module -Path 'C:\Workspace\code\UtilsModule' -Repository 'P ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Publish-Module], InvalidOperationException
    + FullyQualifiedErrorId : ModuleVersionIsAlreadyAvailableInTheGallery,Publish-Module

Possible Solution

A possible solution would be to use the -Force parameter in line 1257 on the master branch in PowerShellGet/PSModule.psm1 like so:

if(-not $Force -and ($currentPSGetItemInfo.Version -eq $moduleInfo.Version))

Context

I'm using a CI/CD process and would like to test the modules I'm developing through the pipeline often, without bumping the version number every time.

This is possible using nuget. If I download the .nupkg from Artifactory and push it with nuget, it overwrites the file without any problem:

PS C:\> nuget push C:\temp\UtilsModule.0.0.1.nupkg -Source PSSnapshots
Pushing UtilsModule.0.0.1.nupkg to 'https://xxxx.jfrog.io/xxxx/api/nuget/xxxxPowerShellRepo-Snapshots'...
  PUT https://xxxx.jfrog.io/xxxx/api/nuget/xxxxPowerShellRepo-Snapshots/
  Created https://xxxx.jfrog.io/xxxx/api/nuget/xxxxPowerShellRepo-Snapshots/ 751ms
Your package was pushed.
PS C:\> nuget push C:\temp\UtilsModule.0.0.1.nupkg -Source PSSnapshots
Pushing UtilsModule.0.0.1.nupkg to 'https://xxxx.jfrog.io/xxxx/api/nuget/xxxxPowerShellRepo-Snapshots'...
  PUT https://xxxx.jfrog.io/xxxx/api/nuget/xxxxPowerShellRepo-Snapshots/
  Created https://xxxx.jfrog.io/xxxx/api/nuget/xxxxPowerShellRepo-Snapshots/ 675ms
Your package was pushed.

Your Environment


PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14409.1012
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14409.1012
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

PS C:\> Get-Module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     1.0        GroupSet                            {BuildResourceCommonParameters, BuildResourceString, GroupSet}
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature...}
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, Enable-WSManCredSSP...}
Script     1.1.6.0    PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-PackageProvider...}
Script     1.5.0.0    PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability...}
Script     1.0        ProcessSet                          {BuildResourceCommonParameters, BuildResourceString, ProcessSet}
Manifest   1.1        PSDesiredStateConfiguration         {Invoke-DscResource, Publish-DscConfiguration, Set-DscLocalConfigurationManager, Start-DscConfiguration...}
Script     1.0        ServiceSet                          {BuildResourceCommonParameters, BuildResourceString, ServiceSet}
Script     1.0        WindowsFeatureSet                   {BuildResourceCommonParameters, BuildResourceString, WindowsFeatureSet}
Script     1.0        WindowsOptionalFeatureSet           {BuildResourceCommonParameters, BuildResourceString, WindowsOptionalFeatureSet}

PS C:\> 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.5.0.0          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, InstallUpdate, NoPathUpdate, Filter, Tag, Includes, DscResource, RoleCapability, Command, AcceptLicense, PublishLocation, ScriptSourceLocation, ScriptPublishLocation
Programs                 3.0.0.0          IncludeWindowsInstaller, IncludeSystemComponent

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia in PowerShellGet/PSModule.psm1 intorno alla riga 1257 e segui il controllo della disponibilità della versione di Publish-Module e la gestione di -Force. Riproduci il problema con i due comandi Publish-Module identici verso il feed PSSnapshots, quindi verifica che la sovrascrittura con -Force sia consentita senza modificare la versione del modulo.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
powershell
Ambito
cli, tooling
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.