安装模块尝试使用错误的 URL 下载包



我的组织中有一个开发人员无法从我们的内部 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:UsersP124629OneDrive - Ceridian HCM IncDocumentsWindowsPowerShellModules'.
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:UsersP124629AppDataLocalTemp1104224955'
VERBOSE: DownloadPackage' - name='xyz.PS.Core',
version='1.0.19206.6',destination='C:UsersP124629AppDataLocalTemp1104224955xyz.PS.Corexyz.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/»
PackageManagementInstall-Package : Package 'xyz.PS.Core' failed to install.
At C:Program FilesWindowsPowerShellModulesPowerShellGet1.0.0.1PSModule.psm1:1809 char:21
+ ...          $null = PackageManagementInstall-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ResourceUnavailable: (C:UsersP12462...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:UsersP124629AppDataLocalTemp1104224955xyz.PS.Corexyz.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:UsersmeDocumentsWindowsPowerShellModules'.
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:UsersmeAppDataLocalTemp1058687073'
VERBOSE: DownloadPackage' - name='xyz.PS.Core',
version='1.0.19206.6',destination='C:UsersmeAppDataLocalTemp1058687073xyz.PS.Corexyz.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:UsersmeAppDataLocalTemp1058687073'
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:UsersmeDocumentsWindowsPowerShellModulesxyz.PS.Core1.0.19206.6' with publisher name ''. Is this module signed by
Microsoft: 'False'.
VERBOSE: Module 'xyz.PS.Core' was installed successfully to path
'C:UsersmeDocumentsWindowsPowerShellModulesxyz.PS.Core1.0.19206.6'.
C:>

请注意以下行:

VERBOSE: DownloadPackage' - name='xyz.PS.Core',
version='1.0.19206.6',destination='C:UsersmeAppDataLocalTemp1058687073xyz.PS.Corexyz.PS.Core.nupkg',
uri='http://devstatic.xyz.com/prdnuget/nuget/Packages(Id='xyz.PS.Core',Version='1.0.19206.6')/Download'

区别在于下载包阶段报告的 uri:

  • 他的机器 - uri='http://devstatic.xyz.com/prdnuget/nuget/'
  • My machine - uri='http://devstatic.xyz.com/prdnuget/nuget/Packages(Id='xyz.PS.核心',版本='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:LOCALAPPDATAMicrosoftWindowsPowerShellPowerShellGet

Directory: C:UsersP124629AppDataLocalMicrosoftWindowsPowerShellPowerShellGet

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 SDKsNuGetPackages
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:LOCALAPPDATAMicrosoftWindowsPowerShellPowerShellGet

Directory: C:UsersmeAppDataLocalMicrosoftWindowsPowerShellPowerShellGet

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:>

区别:

  1. 我的命令提示符不是以PS开头,他的。不知道它是否相关。
  2. 我有一个离线 VS NuGet 源,很可能无关紧要。
  3. 我有nuget.exe在$env:LOCALAPPDATAMicrosoftWindowsPowerShellPowerShellGet,他没有。
  4. 我没有模块Microsoft.PowerShell.SecurityMicrosoft.WSMan.Management.不知道这是否相关。

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

我遇到了同样的问题,一个盒子上的模块路径与另一个盒子不同。我所做的修复是将 nuget 程序集从我的盒子C:Program FilesPackageManagementProviderAssembliesnuget复制到另一个盒子。这解决了问题。我的盒子有一个稍新的版本。

最新更新