【问题标题】:Cannot add powershell snapin, when executing from MSBuild project从 MSBuild 项目执行时无法添加 powershell 管理单元
【发布时间】:2016-05-15 16:45:47
【问题描述】:

我有 powershell 脚本,它添加了 snapin。

if ((get-pssnapin  | select-string "Microsoft.TeamFoundation.PowerShell") -eq $null) { 
     Add-PSSnapin Microsoft.TeamFoundation.PowerShell 
}

从powershell命令行调用时有效

但是,当我从 build.proj(msbuild 项目)调用它时,使用:

<Exec Command="powershell -executionpolicy Unrestricted -Command &quot;&amp; { . \&quot;$(SourceDir)myscript.ps1\&quot;; }&quot;" 
      LogStandardErrorAsError="true" ContinueOnError="false"/>

上面写着:

此计算机上未安装 Windows PowerShell 管理单元“Microsoft.TeamFoundation.PowerShell”。

build.proj(82,5): error : Add-PSSnapin : The Windows PowerShell snap-in 'Microsoft.TeamFoundation.PowerSh
build.proj(82,5): error : ell' is not installed on this computer.

【问题讨论】:

  • 这可能是 MSBuild 运行在 32 位/64 位中,并且仅安装了两者之一的管理单元。我会尝试在 x86 和 x64 PowerShell 控制台中加载管理单元进行检查。
  • 当你说它从命令行工作时,你是指本地还是在构建代理上?什么版本的 TFS?
  • @chief7:我在本地 PC 上运行它。 VS2015 连接到 TFS2013。在 tfs 服务器上我还有另一个问题:Get-ChildItem : A parameter cannot be found that matches parameter name 'Depth'. :)

标签: powershell tfs msbuild


【解决方案1】:

您需要先在构建代理上安装 Microsoft.TeamFoundation.PowerShell 管理单元,然后才能将管理单元添加到会话。我相信它是Microsoft Visual Studio Team Foundation Server 2013 Power Tools 下载的一部分。

正如 Al-Muhandis 在 cmets 中建议的那样,确保它安装在 32 位和 64 位中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多