无法将PowerShell模块发布到PSAlGallery

yqkkidmi  于 2022-12-13  发布在  Shell
关注(0)|答案(1)|浏览(131)

我一直在做我的第一个PS模块,我想在PSGallery上与社区分享我工作的开始。
在PowerShell 7下运行Publish-Module时,我收到以下错误:

Publish-Module -Path "C:\Users\Douda\Projects\PSSymantecCloud\Output\PSSymantecCloud\" -NuGetApiKey $ApiKey -Verbose

错误:

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).  '.

似乎是一个编译问题,由于不支持.NET框架,但我没有安装任何东西,并会假设我的默认Windows 11 + PS7是不够的?
我错过了什么?
已在PS 5.1上尝试,但出现不同的错误

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
ix0qys7i

ix0qys7i1#

PowerShellGet也遇到了同样的问题,必须手动更新其.psm1更改:

<TargetFramework>netcoreapp2.0</TargetFramework>

net6(在我的例子中):

<TargetFramework>net6</TargetFramework>

这种情况会一直发生,直到他们决定修复他们的问题:

因此,暂时可以使用此代码自动更新受影响的文件,以正确的.NET版本为目标(请注意,我将替换为net6,请使用正确的版本,可能是net6,但不能确定)。

另请注意,运行此代码需要提升的会话,否则将出现“拒绝访问”错误

# 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

相关问题