2016-02-09 6 views
4

После обновления для Windows (ноябрь PackageManagement и PowerShellGet модули 1.0.0.1 версии) Я не могу зарегистрировать HTTPS NuGet серверы, как PSRepository больше:Invalid Web Uri ошибка регистр-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. 

ответ

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

Это невероятно. Кто не тестирует, не говоря уже о фактическом использовании, https endpoints? –

+0

Возможно, ошибка более конкретна, чем конечная точка HTTPS NuGet, я не смог отладить модуль C#. –

+0

Это исправлено в юбилейном обновлении, поэтому это обходное решение больше не нужно. –

0

Благодаря Антону пурин я обновил скрипт для это:

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 $ Имя -InstallationPolicy Untrusted вместо Set-PSRepository -Name PSGallery -InstallationPolicy Подозрительные
2) Установка ScriptSourceLocation и ScriptPublishLocation для сценариев PowerShell

1

я тот же вопрос , обновление powershell до 5.1 разрешило проблему.

Смежные вопросы