在VSTS托管代理上使用PowerShellGet [英] Using PowerShellGet on VSTS hosted agents

查看:77
本文介绍了在VSTS托管代理上使用PowerShellGet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在构建过程中使用的是Visual Studio Team Services(VSTS)托管的构建代理.我的构建主要依赖于"PowerShell"步骤,该步骤调用了我在git中拥有的脚本.在此脚本中,我想使用PowerShellGet管理PowerShell模块.例如,我希望能够仅通过运行来安装 pscx . >

I am using Visual Studio Team Services (VSTS) hosted build agents in my build process. My builds mostly rely on the 'PowerShell' step that calls a script that I have in git. From within this script, I would like to manage PowerShell modules using PowerShellGet. For example, I would like to be able to install pscx simply by running

Install-Module -Name pscx

不幸的是,托管代理使用PowerShell 4,并且没有安装PowerShellGet模块.结果,Install-Module功能不可用.

Unfortunately, hosted agents use PowerShell 4 and they don't have the PowerShellGet module installed. As a result, the Install-Module function is not available.

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

Anybody has any suggestion to use the PowerShellGet module on VSTS hosted agent? Note that since I don't have admin rights on this machine, I can't install the msi that installs PowerShellGet for PowerShell 4.

推荐答案

要使用PowerShellGet,需要两个PowerShell模块:

To be able to use PowerShellGet, two PowerShell modules are required:

  • PowerShellGet
  • 包装管理

PowerShell 5提供了这些开箱即用的功能,或者通过PowerShell库中提供的msi安装程序提供了这些功能.

These are available out of the box with PowerShell 5 or through the msi installer available on the PowerShell Gallery.

您可以直接将它们添加到git存储库中(而不是通过msi部署这些模块)(例如:在名为PsModules的文件夹中).您将可以在装有PS5或msi的计算机上使用这些模块.它们通常位于C:\Program Files\WindowsPowerShell\Modules文件夹中.

Instead of deploying these modules through the msi, you can simply add them to your git repository (ex: in a folder named PsModules). You will be able to get a hand on these modules on a machine that has either PS5 or the msi installed. They are usually in the C:\Program Files\WindowsPowerShell\Modules folder.

然后,将PsModules文件夹添加到PSModulePath环境变量中.从那里开始,可以按以下方式使用PowerShellGet:

Then, add the PsModules folders to your PSModulePath environment variable. Starting from there, it is possible to use PowerShellGet as in the following:

$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

这篇关于在VSTS托管代理上使用PowerShellGet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆