I've been working on my first PS module, and wanted to share the beginning of my work with the community on the PSGallery.
When running the Publish-Module
, under PowerShell 7, I get the following error:
Publish-Module -Path "C:\Users\Douda\Projects\PSSymantecCloud\Output\PSSymantecCloud\" -NuGetApiKey $ApiKey -Verbose
Error:
Write-Error: Failed to generate the compressed file for module 'C:\Program Files\dotnet\dotnet.exe failed to pack: error MSBuild version 17.3.2+561848881 for .NET Determining projects to restore... C:\Program
Files\dotnet\sdk\6.0.403\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.EolTargetFrameworks.targets(28,5): warning NETSDK1138: The target framework 'netcoreapp2.0' is out of support and will not receive security updates in the future. Please refer to
https://aka.ms/dotnet-core-support for more information about the support policy.
[C:\Users\XXXX\AppData\Local\Temp\981e0c61-cd9d-434f-a47b-f706deca98c4\Temp.csproj] C:\Program
Files\dotnet\sdk\6.0.403\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.EolTargetFrameworks.targets(28,5): warning NETSDK1138: The target framework 'netcoreapp2.0' is out of support and will not receive security updates in the future. Please refer to
https://aka.ms/dotnet-core-support for more information about the support policy. [C:\Users\XXXX\AppData\Local\Temp\981e0c61-cd9d-434f-a47b-f706deca98c4\Temp.csproj]
C:\Users\XXXX\AppData\Local\Temp\981e0c61-cd9d-434f-a47b-f706deca98c4\Temp.csproj : error NU1100: Unable to resolve 'Microsoft.NETCore.App (>= 2.0.0)' for '.NETCoreApp,Version=v2.0'. Failed to restore
C:\Users\XXXX\AppData\Local\Temp\981e0c61-cd9d-434f-a47b-f706deca98c4\Temp.csproj (in 83 ms). '.
Seems like a compiling issue due to out of support .NET Framework, but I didn't install anything and would assume my default Windows 11 + PS7 isn't enough ?
What am I missing ?
Tried on PS 5.1 with a different error
Publish-PSArtifactUtility : Failed to publish module 'PSSymantecCloud': '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
Had the same problem, the issue is with PowerShellGet, had to manually update their .psm1
changing:
<TargetFramework>netcoreapp2.0</TargetFramework>
To net6
(in my case):
<TargetFramework>net6</TargetFramework>
This will keep happening until they decide to fix their thing:
So for the time being, this code can be used to automatically update the affected file targeting the right .NET Version (do note I'm replacing with net6
, use the correct version for you, likely will be net6
but can't be sure).
Also note, running this code will require an elevated session, or you would get Access Denied errors.
# 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', 'net6') |
Set-Content $_
}
Import-Module PowerShellGet -Force -Verbose
# now try to publish