Ant*_*rin 7 powershell oneget powershellget
在Windows 11月更新(PackageManagement以及PowerShellGet1.0.0.1版本的模块)之后,我无法再将HTTPS NuGet服务器注册为PSRepository:
Register-PSRepository -Name test -SourceLocation https://some-nuget/api/v2
Run Code Online (Sandbox Code Playgroud)
它返回错误:
# Register-PSRepository : The specified Uri 'https://some-nuget/api/v2' for parameter 'SourceLocation' is an invalid Web Uri. Please ensure that it meets the Web Uri requirements.
Run Code Online (Sandbox Code Playgroud)
这是由于与访问HTTPS端点相关的错误导致的,可能很快就会修复.
我还想分享一个由OneGet团队暗示的解决方法:
Function Register-PSRepositoryFix {
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true)]
[String]
$Name,
[Parameter(Mandatory=$true)]
[Uri]
$SourceLocation,
[ValidateSet('Trusted', 'Untrusted')]
$InstallationPolicy = 'Trusted'
)
$ErrorActionPreference = 'Stop'
Try {
Write-Verbose 'Trying to register via ?Register-PSRepository'
?Register-PSRepository -Name $Name -SourceLocation $SourceLocation -InstallationPolicy $InstallationPolicy
Write-Verbose 'Registered via Register-PSRepository'
} Catch {
Write-Verbose 'Register-PSRepository failed, registering via workaround'
# Adding PSRepository directly to file
Register-PSRepository -name $Name -SourceLocation $env:TEMP -InstallationPolicy $InstallationPolicy
$PSRepositoriesXmlPath = "$env:LOCALAPPDATA\Microsoft\Windows\PowerShell\PowerShellGet\PSRepositories.xml"
$repos = Import-Clixml -Path $PSRepositoriesXmlPath
$repos[$Name].SourceLocation = $SourceLocation.AbsoluteUri
$repos[$Name].PublishLocation = (New-Object -TypeName Uri -ArgumentList $SourceLocation, 'package/').AbsoluteUri
$repos[$Name].ScriptSourceLocation = ''
$repos[$Name].ScriptPublishLocation = ''
$repos | Export-Clixml -Path $PSRepositoriesXmlPath
# Reloading PSRepository list
Set-PSRepository -Name PSGallery -InstallationPolicy Untrusted
Write-Verbose 'Registered via workaround'
}
}
Run Code Online (Sandbox Code Playgroud)
像使用普通一样使用它Register-PSRepository:
Register-PSRepositoryFix -Name test -SourceLocation https://some-nuget/api/v2
Run Code Online (Sandbox Code Playgroud)
就我而言,问题在于源位置的(https)服务器仅支持TLS 1.2。
在PowerShell 5.1的Windows 7上运行,默认设置是仅支持SSL3和TLS 1.0。
以下内容使其可以工作:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Register-PSRepository -Name "Artifactory" -SourceLocation "https://example.com/artifactory/api/nuget/powershell/"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5488 次 |
| 最近记录: |