Publish-PSArtifactUtility : Failed to generate the compressed file for module ‘C:\Program Files\dotnet\dotnet.exe failed to pack: error’

Recently I tried to publish a PowerShell module into the gallery from a relatively fresh Windows 10 installation, when the Publish-Module cmdlet failed with an error:

Running Process Monitor, I found the command line it tries to execute looks like this:
"C:\Program Files\dotnet\dotnet.exe" pack "C:\Users\ExampleUser\AppData\Local\Temp\2f2dd498-4ce3-4ca2-a081-c65b0af71090\Temp.csproj" /p:NuspecFile="C:\Users\ExampleUser\AppData\Local\Temp\1691004664\MyModule\MyModule.nuspec" --output "C:\Users\ExampleUser\AppData\Local\Temp\1691004664\MyModule"

My PowerShellGet installation was at the latest stable version, and the NuGet version clearly has nothing to do with it: there were no calls for “nuget.exe” in the Process Monitor log.

So what happens if I run this command manually?

Aha! A descriptive error finally!
Turns out, the pack command is a part of .NET SDK. And of course, since that was a new Windows installation, it did not have that SDK at the moment.

Thankfully, with winget, .NET SDK installation is a breeze: winget install Microsoft.DotNet.SDK.7

Now let’s check what we’ve got:

The error is different now and perfectly logical – I didn’t pass any project file to it.
And it helped – Publish-Module now works! Hooray!

Leave a Reply

Your email address will not be published. Required fields are marked *