powershell - Post Build PowerShell 脚本不包括已安装的模块

标签 powershell cmd msbuild

我在我的后期构建配置中调用以下脚本:

%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/

相关文章:

msbuild - CruiseControl.Net Web 仪表板不显示结果

powershell - 使用 csv 的 ForEach 中的 If 语句

java - 从控制台运行 Java 应用程序时如何查看完整的异常堆栈跟踪?

visual-c++ - <msbuild/> 任务失败而 <devenv/> 在 CruiseControl.NET 中的 MFC 应用程序成功?

batch-file - 批处理文件读取第一行未使用的文本,然后标记为已使用

windows - 批处理文件,文件夹路径中的通配符,不知道通配符是什么

visual-studio-2010 - Web 部署 : Exclude directories depending on Project Configuration name

Python 无法使用 Powershell 找到路径

string - 两个不同大小的对象和 $null

windows - 自动安装 IIS