powershell - 安装 posh-git 时遇到问题

标签 powershell posh-git

我想在笔记本电脑上安装 posh-git,但是当我尝试使用命令“PowerShellGet\Install-Module posh-git -Scope CurrentUser -AllowPrerelease -Force”安装时出现错误:

Install-Module : A parameter cannot be found that matches parameter name
'AllowPrerelease'.
At line:1 char:58
+ ... et\Install-Module posh-git -Scope CurrentUser -AllowPrerelease -Force
+                                                   ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Install-Module], Paramet
   erBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Install-Module

阅读 github 站点上的勘误表,我看到它说我需要使用“Install-Module PowerShellGet -S”更新我的 PowerShellGet 模块
应对 CurrentUser -Force -AllowClobber"但这会产生错误:
PackageManagement\Install-Package : The module 'PackageManagement' cannot be
installed or updated because the authenticode signature of the file
'PackageManagement.cat' is not valid.
At C:\Program
Files\WindowsPowerShell\Modules\PowerShellGet\1.0.0.1\PSModule.psm1:1809
char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Power....InstallP
   ackage:InstallPackage) [Install-Package], Exception
    + FullyQualifiedErrorId : InvalidAuthenticodeSignature,ValidateAndGet-Au
   thenticodeSignature,Microsoft.PowerShell.PackageManagement.Cmdlets.Insta
  llPackage

我已经用谷歌搜索并尝试了几种方法来从我的笔记本电脑上显示的 v1.0.0.1 更新 PowerShellGet,但都无济于事。任何有关如何纠正此问题的建议将不胜感激。

最佳答案

错误是具体的。您正在为模块使用默认情况下不存在的参数/开关。

# get function / cmdlet details
(Get-Command -Name Install-Module).Parameters.Keys
<#
Name
InputObject
MinimumVersion
MaximumVersion
RequiredVersion
Repository
Credential
Scope
Proxy
ProxyCredential
AllowClobber
SkipPublisherCheck
Force
Verbose
Debug
ErrorAction
WarningAction
InformationAction
ErrorVariable
WarningVariable
InformationVariable
OutVariable
OutBuffer
PipelineVariable
WhatIf
Confirm
#>
Get-help -Name Install-Module -Examples
Get-help -Name Install-Module -Full
Get-help -Name Install-Module -Online

根据文档:

Prerelease Versioning Added to PowerShellGet and PowerShell Gallery

开发人员必须添加此内容,否则无法使用。

Publishers simply add the prerelease string (ie. the part that comes after “2.0.0”) in the metadata, and the version will be considered prerelease. For example:


@{
   ModuleVersion = '2.0.0'
   #---
      PrivateData = @{
         PSData = @{
            Prerelease = '-alpha'
      }
   }
}

这...
PowerShellGet\Install-Module

…也不是关于如何安装模块的常用方法(我知道)。您应该只需要 Install-Module cmdlet,PowerShell 已经知道它来自的模块并自动加载该模块(如果尚未加载)。

试试这个...
Find-Module -Name posh-git

Version    Name       Repository           Description
-------    ----       ----------           -----------
0.7.3      posh-git   PSGallery            Provides prompt ...



Find-Module -Name posh-git | 
Save-Module -Path "$env:USERPROFILE\Documents\WindowsPowerShell\Modules" # -WhatIf

What if: Performing the operation "Save Package" on target "'posh-git' to location 'C:\Users\Daniel\Documents\WindowsPowerShell\Modules'".


Install-Module -Name posh-git -Scope CurrentUser -Force

关于powershell - 安装 posh-git 时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53974626/

相关文章:

powershell - 如何在Windows 8上安装最新的Powershell?

powershell - 如何从命令行启动 PowerShell(不是脚本)

git - 当指定 --no-color 时,不要使用 git log --pretty 对引用进行着色

powershell - 是否可以为单个存储库禁用 posh-git?

xml - 删除 XML 节点以将 XML 日志文件的大小减小到给定大小

string - 如何在Powershell中两次评估字符串

arrays - PowerShell 中的 JSON 数组

git - 如何使用 powershell 和批处理文件从实时网站自动每晚推送到 GitHub 分支

git - Powershell 在每次 pull 时而不是在启动时要求 git RSA 密码?

git - 为什么在 powershell 和 posh git 中没有黄色