windows - Install-Module 尝试使用错误的 url 下载包

标签 windows powershell

我的组织中有一个开发人员无法从我们的内部 NuGet 存储库安装 powershell 模块。他和我有相同的PowershellGet版本,但我没有这样的问题。

他的机器

PS C:\> install-module xyz.ps.core -Scope CurrentUser -Force -Verbose
VERBOSE: Using the provider 'PowerShellGet' for searching packages.
VERBOSE: The -Repository parameter was not specified.  PowerShellGet will use all of the registered repositories.
VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.
VERBOSE: The specified Location is 'http://devstatic.xyz.com/prdnuget/nuget' and PackageManagementProvider is 'NuGet'.
VERBOSE: Searching repository 'http://devstatic.xyz.com/prdnuget/nuget/FindPackagesById()?id='xyz.ps.core'' for ''.
VERBOSE: Total package yield:'1' for the specified package 'xyz.ps.core'.
VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.
VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2' and PackageManagementProvider is 'NuGet'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='xyz.ps.core'' for ''.
VERBOSE: Total package yield:'0' for the specified package 'xyz.ps.core'.
VERBOSE: Performing the operation "Install-Module" on target "Version '1.0.19206.6' of module 'xyz.PS.Core'".
VERBOSE: The installation scope is specified to be 'CurrentUser'.
VERBOSE: The specified module will be installed in 'C:\Users\P124629\OneDrive - Ceridian HCM Inc\Documents\WindowsPowerShell\Modules'.
VERBOSE: The specified Location is 'NuGet' and PackageManagementProvider is 'NuGet'.
VERBOSE: Downloading module 'xyz.PS.Core' with version '1.0.19206.6' from the repository 'http://devstatic.xyz.com/prdnuget/nuget'.
VERBOSE: Searching repository 'http://devstatic.xyz.com/prdnuget/nuget/FindPackagesById()?id='xyz.PS.Core'' for ''.
VERBOSE: InstallPackage' - name='xyz.PS.Core', version='1.0.19206.6',destination='C:\Users\P124629\AppData\Local\Temp\1104224955'
VERBOSE: DownloadPackage' - name='xyz.PS.Core',
version='1.0.19206.6',destination='C:\Users\P124629\AppData\Local\Temp\1104224955\xyz.PS.Core\xyz.PS.Core.nupkg',
uri='http://devstatic.xyz.com/prdnuget/nuget/'
VERBOSE: Downloading 'http://devstatic.xyz.com/prdnuget/nuget/package/xyz.PS.Core/1.0.19206.6'.
WARNING: Could not get response from query 'http://devstatic.xyz.com/prdnuget/nuget/package/xyz.PS.Core/1.0.19206.6'.
VERBOSE: Downloading package 'xyz.PS.Core' failed, please make sure 'http://devstatic.xyz.com/prdnuget/nuget/package/xyz.PS.Core/1.0.19206.6' is
accessable.
WARNING: MSG:SourceLocationNotValid «http://devstatic.xyz.com/prdnuget/nuget/»
PackageManagement\Install-Package : Package 'xyz.PS.Core' failed to install.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809 char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (C:\Users\P12462...e.PS.Core.nupkg:String) [Install-Package], Exception
    + FullyQualifiedErrorId : PackageFailedInstallOrDownload,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

PS C:\>

请注意以下行:
VERBOSE: DownloadPackage' - name='xyz.PS.Core',
version='1.0.19206.6',destination='C:\Users\P124629\AppData\Local\Temp\1104224955\xyz.PS.Core\xyz.PS.Core.nupkg',
uri='http://devstatic.xyz.com/prdnuget/nuget/'

我的机器
C:\> Install-Module xyz.PS.Core -Scope CurrentUser -Force -Verbose
VERBOSE: Using the provider 'PowerShellGet' for searching packages.
VERBOSE: The -Repository parameter was not specified.  PowerShellGet will use all of the registered repositories.
VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.
VERBOSE: The specified Location is 'http://devstatic.xyz.com/prdnuget/nuget' and PackageManagementProvider is 'NuGet'.
VERBOSE: Searching repository 'http://devstatic.xyz.com/prdnuget/nuget/FindPackagesById()?id='xyz.PS.Core'' for ''.
VERBOSE: Total package yield:'1' for the specified package 'xyz.PS.Core'.
VERBOSE: Getting the provider object for the PackageManagement Provider 'NuGet'.
VERBOSE: The specified Location is 'https://www.powershellgallery.com/api/v2' and PackageManagementProvider is 'NuGet'.
VERBOSE: Searching repository 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='xyz.PS.Core'' for ''.
VERBOSE: Total package yield:'0' for the specified package 'xyz.PS.Core'.
VERBOSE: Performing the operation "Install-Module" on target "Version '1.0.19206.6' of module 'xyz.PS.Core'".
VERBOSE: The installation scope is specified to be 'CurrentUser'.
VERBOSE: The specified module will be installed in 'C:\Users\me\Documents\WindowsPowerShell\Modules'.
VERBOSE: The specified Location is 'NuGet' and PackageManagementProvider is 'NuGet'.
VERBOSE: Downloading module 'xyz.PS.Core' with version '1.0.19206.6' from the repository
'http://devstatic.xyz.com/prdnuget/nuget'.
VERBOSE: Searching repository 'http://devstatic.xyz.com/prdnuget/nuget/FindPackagesById()?id='xyz.PS.Core'' for ''.
VERBOSE: InstallPackage' - name='xyz.PS.Core',
version='1.0.19206.6',destination='C:\Users\me\AppData\Local\Temp\1058687073'
VERBOSE: DownloadPackage' - name='xyz.PS.Core',
version='1.0.19206.6',destination='C:\Users\me\AppData\Local\Temp\1058687073\xyz.PS.Core\xyz.PS.Core.nupkg',
uri='http://devstatic.xyz.com/prdnuget/nuget/Packages(Id='xyz.PS.Core',Version='1.0.19206.6')/Download'
VERBOSE: Downloading 'http://devstatic.xyz.com/prdnuget/nuget/Packages(Id='xyz.PS.Core',Version='1.0.19206.6')/Download'.
VERBOSE: Completed downloading
'http://devstatic.xyz.com/prdnuget/nuget/Packages(Id='xyz.PS.Core',Version='1.0.19206.6')/Download'.
VERBOSE: Completed downloading 'xyz.PS.Core'.
VERBOSE: Hash for package 'xyz.PS.Core' does not match hash provided from the server.
VERBOSE: InstallPackageLocal' - name='xyz.PS.Core',
version='1.0.19206.6',destination='C:\Users\me\AppData\Local\Temp\1058687073'
VERBOSE: Catalog file 'xyz.PS.Core.cat' is not found in the contents of the module 'xyz.PS.Core' being installed.
VERBOSE: For publisher validation, current module 'xyz.PS.Core' with version '1.0.19206.6' with publisher name ''. Is this module
signed by Microsoft: 'False'.
VERBOSE: For publisher validation, using the previously-installed module 'xyz.PS.Core' with version '1.0.19206.6' under
'C:\Users\me\Documents\WindowsPowerShell\Modules\xyz.PS.Core\1.0.19206.6' with publisher name ''. Is this module signed by
Microsoft: 'False'.
VERBOSE: Module 'xyz.PS.Core' was installed successfully to path
'C:\Users\me\Documents\WindowsPowerShell\Modules\xyz.PS.Core\1.0.19206.6'.
C:\>

请注意以下行:
VERBOSE: DownloadPackage' - name='xyz.PS.Core',
version='1.0.19206.6',destination='C:\Users\me\AppData\Local\Temp\1058687073\xyz.PS.Core\xyz.PS.Core.nupkg',
uri='http://devstatic.xyz.com/prdnuget/nuget/Packages(Id='xyz.PS.Core',Version='1.0.19206.6')/Download'

不同之处在于 DownloadPackage 阶段报告的 uri:
  • 他的机器 - uri=' http://devstatic.xyz.com/prdnuget/nuget/ '
  • 我的机器 - uri=' http://devstatic.xyz.com/prdnuget/nuget/Packages(Id= 'xyz.PS.Core',Version='1.0.19206.6')/下载'

  • 我不明白如何解决这个问题。他安装了和我一样的 PS 模块。

    任何想法如何解决这个问题?

    (我们在 Windows 10 上使用 Powershell 5.1)

    编辑 1

    他的机器
    PS C:\> Get-PackageSource
    
    Name                             ProviderName     IsTrusted  Location
    ----                             ------------     ---------  --------
    nuget.org                        NuGet            False      https://api.nuget.org/v3/index.json
    xyz                              PowerShellGet    True       http://devstatic.xyz.com/prdnuget/nuget
    PSGallery                        PowerShellGet    True       https://www.powershellgallery.com/api/v2
    
    
    PS C:\> dir $env:LOCALAPPDATA\Microsoft\Windows\PowerShell\PowerShellGet
    
    
        Directory: C:\Users\P124629\AppData\Local\Microsoft\Windows\PowerShell\PowerShellGet
    
    
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    -a----        7/25/2019   1:31 PM           5674 PSRepositories.xml
    
    
    PS C:\> $PSVersionTable
    
    Name                           Value
    ----                           -----
    PSVersion                      5.1.17763.592
    PSEdition                      Desktop
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
    BuildVersion                   10.0.17763.592
    CLRVersion                     4.0.30319.42000
    WSManStackVersion              3.0
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    
    
    PS C:\> Get-Module
    
    ModuleType Version    Name                                ExportedCommands
    ---------- -------    ----                                ----------------
    Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}
    Manifest   3.0.0.0    Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-...
    Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
    Manifest   3.0.0.0    Microsoft.WSMan.Management          {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, Enable-W...
    Binary     1.0.0.1    PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-PackagePro...
    Script     1.0.0.1    PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCapabilit...
    Script     2.0.0      PSReadline                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLi...
    
    
    PS C:\>
    

    我的机器
    C:\> Get-PackageSource
    
    Name                             ProviderName     IsTrusted  Location
    ----                             ------------     ---------  --------
    Microsoft Visual Studio Offli... NuGet            False      C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
    NuGet.org                        NuGet            False      https://api.nuget.org/v3/index.json
    xyz                              PowerShellGet    True       http://devstatic.xyz.com/prdnuget/nuget
    PSGallery                        PowerShellGet    True       https://www.powershellgallery.com/api/v2
    
    
    C:\> dir $env:LOCALAPPDATA\Microsoft\Windows\PowerShell\PowerShellGet
    
    
        Directory: C:\Users\me\AppData\Local\Microsoft\Windows\PowerShell\PowerShellGet
    
    
    Mode                LastWriteTime         Length Name
    ----                -------------         ------ ----
    -a----        4/12/2019   8:04 PM        1686528 NuGet.exe
    -a----        7/26/2019  12:06 PM           5328 PSRepositories.xml
    
    
    C:\> $PSVersionTable
    
    Name                           Value
    ----                           -----
    PSVersion                      5.1.17763.592
    PSEdition                      Desktop
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
    BuildVersion                   10.0.17763.592
    CLRVersion                     4.0.30319.42000
    WSManStackVersion              3.0
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    
    
    C:\> Get-Module
    
    ModuleType Version    Name                                ExportedCommands
    ---------- -------    ----                                ----------------
    Script     1.0.192... xyz.PS.Core                         {Add-ComputedFieldsToBuild, Add-xyzDatabaseIfNotFound, Assert-Elevated,...
    Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}
    Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
    Binary     1.0.0.1    PackageManagement                   {Find-Package, Find-PackageProvider, Get-Package, Get-PackageProvider...}
    Script     1.0.0.1    PowerShellGet                       {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability...}
    Script     2.0.0      PSReadline                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler...
    
    
    C:\>
    

    区别:
  • 我的命令提示符不是以 PS 开头,他的。不知道是否相关。
  • 我有一个离线的 VS NuGet 源,很可能没关系。
  • 我在 $env:LOCALAPPDATA\Microsoft\Windows\PowerShell\PowerShellGet 中有 nuget.exe , 他没有。
  • 我没有模块 Microsoft.PowerShell.SecurityMicrosoft.WSMan.Management .不知道这是否相关。

  • 运行 procmon.exe 并过滤到 nuget.exe 不会显示 Install-Module在我的机器上运行它。似乎它通过 nuget 客户端 dll 进入 NuGet 逻辑。为了证明我的观点,我在我的机器上重命名了这个文件并 Install-Module仍然可以正常工作。

    最佳答案

    我遇到了同样的问题,一个盒子上的模块路径与另一个不同。我修复它的方法是从 C:\Program Files\PackageManagement\ProviderAssemblies\nuget 复制 nuget 程序集。从我的盒子到另一个盒子。这解决了这个问题。我的盒子有一个稍新的版本。

    关于windows - Install-Module 尝试使用错误的 url 下载包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57223747/

    相关文章:

    windows - 在Windows上解压缩.tar.gz文件

    c++ - C++ 库中的文件打开接口(interface)应该在 Windows 上使用 UTF-8 吗?

    ruby-on-rails - 为什么rails.bat 可以工作,而rails 却不能?

    C 运行时库问题 MD/MDd

    powershell - 设置服务: Cannot stop service because it is dependent on other services

    powershell - 有什么方法可以使用 powershell 命令安装虚拟音频电缆应用程序而无需提示消息

    powershell - 从 psm 函数的脚本 block 中定义的获取变量

    c# - Windows - 将程序用作虚拟打印机?

    powershell - 在 Powershell 中将文件内容与字符串进行比较

    powershell - 如何在powershell中使用 'dry-run'