简体   繁体   English

TFS发布构建Powershell脚本看不到导入模块的命令

[英]TFS post build powershell script not seeing commands from imported module

We have a TFS build process using a custom template. 我们有一个使用自定义模板的TFS构建过程。 The build works fine with the crm solution files successfully being created. 在成功创建crm解决方案文件的情况下,构建可以正常工作。 We are then attempting to run a powershell script on the post build. 然后,我们尝试在构建后的版本上运行Powershell脚本。 This script imports a module. 该脚本导入一个模块。 But the commands in the module are not being exposed. 但是模块中的命令并未公开。 Whenever we attempt to invoke a command, we get an error. 每当我们尝试调用命令时,都会出现错误。 Along the lines of 沿线

The term 'Get-XrmSolution' is not recognized as the name of a cmdlet, function, script file, or operable program. 术语“ Get-XrmSolution”不被视为cmdlet,函数,脚本文件或可运行程序的名称。

It doesn't matter which command we use in that module, we get the same kind of error. 在该模块中使用哪个命令都没有关系,我们会得到相同的错误。

To troubleshoot, we have logged onto the build server under the identity of the build account and can successfully run the script we are attempting to run. 为了进行故障排除,我们已经以构建帐户的身份登录到构建服务器,并且可以成功运行我们尝试运行的脚本。

Putting some more output into the script to troubleshoot... 将更多输出输出到脚本中以进行故障排除...

Get-Module lists Xrm.Framework.CI.PowerShell. Get-Module列出Xrm.Framework.CI.PowerShell。 - Good. 很好

Get-Command -Module "Xrm.Framework.CI.PowerShell" returns nothing. Get-Command -Module "Xrm.Framework.CI.PowerShell"返回任何内容。 From the console, a number of commands are listed. 在控制台中,列出了许多命令。

Is there something we need to do with the running of powershell post build scripts to enable the contents of an imported module to be seen? 我们需要运行powershell post build脚本来使导入模块的内容可见吗?

IIRC you have to explicitly import the module with no assumption of being loaded on user profile, nor on the script path. IIRC,您必须显式导入模块,而无需假设已在用户配置文件或脚本路径上加载了该模块。 Suppose Module1.psm1 is in the same folder as your script, use something like 假设Module1.psm1与脚本位于同一文件夹中,请使用类似

Import-Module (Join-Path (Split-Path -Parent $MyInvocation.MyCommand.Definition) 'Module1.psm1')

Watch out for the bitness of PowerShell invoked by MSBuild and likewise, the bitness of MSBuild launched by Visual Studio. 请注意由MSBuild调用的PowerShell的细节,以及由Visual Studio启动的MSBuild的细节。 Certain modules only run in either 32-bit or 64-bit PowerShell and not both. 某些模块只能在32位或64位PowerShell中运行,而不能同时在两者中运行。 You want to make sure the correct version of PowerShell is getting launched. 您要确保启动正确的PowerShell版本。

I had the same problem. 我有同样的问题。

The module was loaded in the 'C:\\Program Files\\WindowsPowerShell\\Modules' folder (64 bits). 该模块已加载到“ C:\\ Program Files \\ WindowsPowerShell \\ Modules”文件夹中(64位)。

It all seemed fine when I logged on as the user, but it failed during TFS build. 当我以用户身份登录时,一切似乎都很好,但是在TFS构建期间失败了。

Solution: I had to uninstall the module in PowerShell 64 bit and re-install in PowerShell 32 bit. 解决方案:我必须在PowerShell 64位中卸载该模块,然后在PowerShell 32位中重新安装。

The module was then installed in 'C:\\Program Files (x86)\\WindowsPowerShell\\Modules' folder. 然后将该模块安装在“ C:\\ Program Files(x86)\\ WindowsPowerShell \\ Modules”文件夹中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM