我在我的后期构建配置中调用以下脚本:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -ExecutionPolicy RemoteSigned -file "\Sclddev8\tfs\Scripts\slack-notice.ps1" -Verb RunAs;
但是,我不断收到此错误:
Send-SlackMessage : The term 'Send-SlackMessage' is not recognized as the name
但是我已经在我的环境中安装了这个模块,如果我打开一个 PowerShell 控制台或在这个构建过程之外运行文件,则可以正常工作。
最佳答案
安装 Powershell 模块时,从技术上讲,每次打开新的 Powershell 窗口时都会从配置文件中导入模块。通过使用“-NoProfile”开关运行 Powershell,您可以阻止导入模块(即使它已“安装”并且文件存在)。
如果您想保持“-NoProfile”开关处于事件状态,那么您最好的选择是在脚本顶部有一行来导入模块,然后再继续。如果您使用 Warren Frame 的“PSSlack”模块,您需要的命令是:
> Import-Module PSSlack
关于powershell - Post Build PowerShell 脚本不包括已安装的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46918471/