1
Publish-Script -Path "path-to-script.ps1" -NuGetApiKey 123456789

after doing that, I get this error in PowerShell 7.3:

Write-Error: Failed to generate the compressed file for script 'C:\Program Files\dotnet\dotnet.exe failed to pack: error  '. 

and I get this error in PowerShell 5.1:

Publish-PSArtifactUtility : Failed to generate the compressed file for script 'C:\Program Files\dotnet\dotnet.exe
failed to pack: error
'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.5\PSModule.psm1:11338 char:17
+ ...             Publish-PSArtifactUtility @PublishPSArtifactUtility_Param ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : FailedToCreateCompressedScript,Publish-PSArtifactUtility

my script has no dependency.

this problem has been going on for the past 2 weeks.

I even gave my script with API key to a friend from another country and they receive the same error too. how can I fix this? I've published previous versions of this script before at least 6 times.

I've tried resetting my API key and running PowerShell as admin, didn't fix it.

Update:

I installed .NET 7 runtimes x64 and used this command from this answer on PowerShell 5.1:

# find the file having wrong .NET version
$path = Get-ChildItem (Get-Module PowerShellGet -ListAvailable).ModuleBase -Recurse -File |
    Select-String -Pattern netcoreapp2.0 | ForEach-Object Path

# unload the module
Remove-Module PowerShellGet -Verbose -Force -EA 0

# update the file
$path | ForEach-Object {
    (Get-Content -LiteralPath $_ -Raw).Replace('netcoreapp2.0', 'net7') |
        Set-Content $_
}

Import-Module PowerShellGet -Force -Verbose

# now try to publish

but still getting error:

Publish-PSArtifactUtility : Failed to generate the compressed file for script 'C:\Program Files\dotnet\dotnet.exe
failed to pack: error
'.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2.5\PSModule.psm1:11338 char:17
+ ...             Publish-PSArtifactUtility @PublishPSArtifactUtility_Param ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : FailedToCreateCompressedScript,Publish-PSArtifactUtility

enter image description here

  • Have a look here https://stackoverflow.com/q/74548911/15339544 I think your issue is probably related – Santiago Squarzon Dec 04 '22 at 14:26
  • Should I install .NET runtime? –  Dec 04 '22 at 14:39
  • No, see the answer, the issue is not your .NET Version. The issue is PowerShellGet team not updating their module properly. – Santiago Squarzon Dec 04 '22 at 14:43
  • @SantiagoSquarzon please take a look at my question, I updated it. added a screenshot of the exact part where PowerShell is complaining about in the module. –  Dec 04 '22 at 14:57

1 Answers1

0

I fixed the problem by installing .NET Core 2.0 SDK

https://dotnet.microsoft.com/en-us/download/dotnet/thank-you/sdk-2.1.202-windows-x64-installer