10

Windows の 11 月の更新 (PackageManagementおよびPowerShellGet1.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.
4

5 に答える 5

11

これは、おそらくすぐに修正される 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'
    }
}

通常と同じように使用しますRegister-PSRepository

Register-PSRepositoryFix -Name test -SourceLocation https://some-nuget/api/v2
于 2016-02-09T15:58:56.403 に答える
1

-Credentialこのエラーは、間違ったユーザー名またはパスワードで渡すことによっても (誤って) 発生します。

于 2021-07-27T17:20:11.133 に答える