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:
1 2 3 4 5 6 |
Publish-PSArtifactUtility : Failed to generate the compressed file for module 'C:\Program Files\dotnet\dotnet.exe failed to pack: error'. At C:\Users\example\Documents\WindowsPowerShell\Modules\PowerShellGet\2.2.5\PSModule.psm1:10990 char:17 + ... Publish-PSArtifactUtility @PublishPSArtifactUtility_Param ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : FailedToCreateCompressedModule,Publish-PSArtifactUtility |
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?
1 2 3 4 5 6 7 8 9 10 11 12 13 |
PS > &'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" The command could not be loaded, possibly because: * You intended to execute a .NET application: The application 'pack' does not exist. * You intended to execute a .NET SDK command: No .NET SDKs were found. Download a .NET SDK: https://aka.ms/dotnet-download Learn about SDK resolution: https://aka.ms/dotnet/sdk-not-found |
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
PS > &'C:\Program Files\dotnet\dotnet.exe' pack Welcome to .NET 7.0! --------------------- SDK Version: 7.0.202 Telemetry --------- The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell. Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry ---------------- Installed an ASP.NET Core HTTPS development certificate. To trust the certificate run 'dotnet dev-certs https --trust' (Windows and macOS only). Learn about HTTPS: https://aka.ms/dotnet-https ---------------- Write your first app: https://aka.ms/dotnet-hello-world Find out what's new: https://aka.ms/dotnet-whats-new Explore documentation: https://aka.ms/dotnet-docs Report issues and find source on GitHub: https://github.com/dotnet/core Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli -------------------------------------------------------------------------------------- MSBuild version 17.5.0+6f08c67f3 for .NET MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file. |
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!