Windows 11月更新(PackageManagement
和PowerShellGet
1.0.0.1版本的模块)之后,我无法再将HTTPS NuGet服务器注册为PSRepository:
Register-PSRepository -Name test -SourceLocation https://some-nuget/api/v2
它返回错误:
# 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.
答案 0 :(得分:7)
这是由于与访问HTTPS端点相关的错误导致的,可能很快就会修复。
我仍然希望分享OneGet team暗示的一种解决方法:
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'
}
}
像使用普通Register-PSRepository
:
Register-PSRepositoryFix -Name test -SourceLocation https://some-nuget/api/v2
答案 1 :(得分:3)
就我而言,问题是源位置的(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/"
答案 2 :(得分:1)
我有同样的问题,将powershell更新到5.1解决了这个问题。
答案 3 :(得分:0)
感谢Anton Purin,我已将他的剧本更新为:
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 = (New-Object -TypeName Uri -ArgumentList $SourceLocation, 'items/psscript/').AbsoluteUri
$repos[$Name].ScriptPublishLocation = (New-Object -TypeName Uri -ArgumentList $SourceLocation, 'package/').AbsoluteUri
$repos | Export-Clixml -Path $PSRepositoriesXmlPath
# Reloading PSRepository list
Set-PSRepository -Name $Name -InstallationPolicy Untrusted
Write-Verbose 'Registered via workaround'
}
}
# Usage Example
Register-PSRepositoryFix -Name "Name" -SourceLocation "http://address:port/api/v2/" -Verbose
两个主要区别是:
1)
Set-PSRepository -Name $ Name -InstallationPolicy Untrusted
代替
Set-PSRepository -Name PSGallery -InstallationPolicy Untrusted
2)为PowerShell脚本设置ScriptSourceLocation和ScriptPublishLocation
答案 4 :(得分:0)
该错误也是(错误地)由使用错误的用户名或密码传递 -Credential
引起的。