【问题标题】:Using PowerShellGet on VSTS hosted agents在 VSTS 托管代理上使用 PowerShellGet
【发布时间】:2016-04-30 11:22:21
【问题描述】:

我在构建过程中使用 Visual Studio Team Services (VSTS) 托管的构建代理。我的构建主要依赖于调用我在 git 中的脚本的“PowerShell”步骤。在这个脚本中,我想使用 PowerShellGet 管理 PowerShell 模块。例如,我希望能够通过运行来安装pscx

Install-Module -Name pscx

不幸的是,托管代理使用 PowerShell 4,并且没有安装 PowerShellGet 模块。因此,Install-Module 函数不可用。

有人对在 VSTS 托管代理上使用 PowerShellGet 模块有什么建议吗?请注意,由于我在这台机器上没有管理员权限,因此我无法安装为 PowerShell 4 安装 PowerShellGet 的 msi。

【问题讨论】:

    标签: azure-devops azure-pipelines azure-pipelines-build-task powershellget


    【解决方案1】:

    为了能够使用 PowerShellGet,需要两个 PowerShell 模块:

    • PowerShellGet
    • 包管理

    这些可通过 PowerShell 5 开箱即用或通过 PowerShell 库中的 msi 安装程序获得。

    您可以简单地将它们添加到您的 git 存储库(例如:在名为 PsModules 的文件夹中),而不是通过 msi 部署这些模块。您将能够在安装了 PS5 或 msi 的机器上使用这些模块。它们通常位于C:\Program Files\WindowsPowerShell\Modules 文件夹中。

    然后,将 PsModules 文件夹添加到您的 PSModulePath 环境变量中。从那里开始,可以使用 PowerShellGet,如下所示:

    $env:PSModulePath = "$env:BUILD_SOURCESDIRECTORY\PsModules;$env:PSModulePath"
    Import-Module PowerShellGet
    Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Scope currentuser
    Save-Module pscx -path "$env:BUILD_SOURCESDIRECTORY\PsModules"
    import-module pscx
    Write-Host '************************'
    Get-Command -module pscx
    

    【讨论】:

      猜你喜欢
      • 2019-07-09
      • 1970-01-01
      • 2018-06-15
      • 1970-01-01
      • 1970-01-01
      • 2018-03-02
      • 1970-01-01
      • 2018-10-22
      • 1970-01-01
      相关资源
      最近更新 更多