PowerShell / PowerShellGallery

221 stars 61 forks source link

Unable to publish modules (TLS issue?) #148

Closed JeremyTBradshaw closed 3 years ago

JeremyTBradshaw commented 3 years ago

I've tried from multiple computers where I've previously been able to Publish-Module no problem. I'm getting this:

>Publish-Module -Name MSGraphPSEssentials -NuGetApiKey '<my NuGetApiKey (tried regen., new, no dice)>'
Publish-PSArtifactUtility : Failed to publish module 'MSGraphPSEssentials': 'The underlying connection was closed: An
unexpected error occurred on a send.
'.
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

I checked the status on this repo's main readme, but it shows an old date, and up.

JeremyTBradshaw commented 3 years ago

I was able to get this working just now. While I had the same issue last night and earlier this morning, using both PowerShell 7.1.0 and Windows PowerShell 5.1, just now it finally worked using PowerShell 7.1.0.

I was prompted to install newer Nuget.exe:

NuGet.exe is required to continue
This version of PowerShellGet requires minimum version '4.1.0' of NuGet.exe to publish an item to the NuGet-based
repositories. NuGet.exe must be available in 'C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet\' or
'C:\Users\j\AppData\Local\Microsoft\Windows\PowerShell\PowerShellGet\', or under one of the paths specified in PATH
environment variable value. NuGet.exe can be downloaded from https://aka.ms/psget-nugetexe. For more information, see
https://aka.ms/installing-powershellget . Do you want PowerShellGet to install the latest version of NuGet.exe now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y

I am 99% sure I did in fact try in PowerShell 7.1.0 earlier this morning and last night, however, considering that prompt, I'm questioning myself. I'll just leave this issue open and you guys can feel free to close it.

danjagnow commented 3 years ago

I have observed this behavior, too. I got much better information with verbose logging after installing PowerShell 7.1 than when running Publish-Module under PowerShell 5.1. Under PowerShell 5.1, the underlying connection is closed:

PS C:\Program Files (x86)\WindowsPowerShell\Modules\MyModule> Publish-Module -Name MyModule -NuGetApiKey <key here> -Verbose
...
Publish-PSArtifactUtility : Failed to publish module 'MyModule': 'The underlying connection was closed: An
unexpected error occurred on a send.
'.
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

(with fictitious PowerShell module names, versions, and keys) But under PowerShell 7.1, I get a more meaningful error message:

...
Write-Error: C:\program files\powershell\7\Modules\PowerShellGet\PSModule.psm1:10990
 Line |
10990 |  …             Publish-PSArtifactUtility @PublishPSArtifactUtility_Param …
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      | Failed to publish module 'MyModule': 'dotnet cli failed to nuget push Pushing
      | MyModule.1.0.0.0.nupkg to 'https://www.powershellgallery.com/api/v2/package/'...   PUT
      | https://www.powershellgallery.com/api/v2/package/   Forbidden
...
lelloz0 commented 3 months ago
NuGet.exe is required to continue
This version of PowerShellGet requires minimum version '4.1.0' of NuGet.exe to publish an item to the NuGet-based
repositories. NuGet.exe must be available in 'C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet\' or
'C:\Users\j\AppData\Local\Microsoft\Windows\PowerShell\PowerShellGet\', or under one of the paths specified in PATH
environment variable value. NuGet.exe can be downloaded from https://aka.ms/psget-nugetexe. For more information, see
https://aka.ms/installing-powershellget . Do you want PowerShellGet to install the latest version of NuGet.exe now?
[Y] Yes  [N] No  [S] Suspend  [?] Help (default is "Y"): y

So this message is half a lie: on PowerShell 5.1 you must place (if you can't get to the internet) nuget.exe under C:\ProgramData\Microsoft\Windows\PowerShell\PowerShellGet\ to make it work. I tried C:\Windows which is a path specified in the PATH env var value but it didn't work.