TFS Build: `Microsoft.TeamFoundation.PowerShell

2019-01-15 15:04发布

问题:

When I'm logged in to tfs build server using local account and execute following powershell command:

Add-PSSnapin Microsoft.TeamFoundation.PowerShell

it loads the tfs cmdlets correctly. However, when I trigger a build on tfs server that invokes the script, it fails with message:

'Microsoft.TeamFoundation.PowerShell' is not installed on this computer.

The build agent runs under service account. What should I do?

EDIT: I had to edit the reqistry entry from the first link in @Alexis Coles' answer to make it work with version 2015 of TFS PowerTools:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns\Microsoft.TeamFoundation.PowerShell]
"PowerShellVersion"="4.0"
"Vendor"="Microsoft Corporation"
"Description"="This is a PowerShell snap-in that includes the Team Foundation Server cmdlets."
"VendorIndirect"="Microsoft.TeamFoundation.PowerShell,Microsoft"
"DescriptionIndirect"="Microsoft.TeamFoundation.PowerShell,This is a PowerShell snap-in that includes the Team Foundation Server cmdlets."
"Version"="14.0.0.0"
"ApplicationBase"="C:\\Program Files (x86)\\Microsoft Team Foundation Server 2015 Power Tools"
"AssemblyName"="Microsoft.TeamFoundation.PowerTools.PowerShell, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
"ModuleName"="C:\\Program Files (x86)\\Microsoft Team Foundation Server 2015 Power Tools\\Microsoft.TeamFoundation.PowerTools.PowerShell.dll"
"CustomPSSnapInType"="Microsoft.TeamFoundation.PowerTools.PowerShell.TFPSSnapIn"

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\PowerShell\1\PowerShellSnapIns\Microsoft.TeamFoundation.PowerShell]
"PowerShellVersion"="4.0"
"Vendor"="Microsoft Corporation"
"Description"="This is a PowerShell snap-in that includes the Team Foundation Server cmdlets."
"VendorIndirect"="Microsoft.TeamFoundation.PowerShell,Microsoft"
"DescriptionIndirect"="Microsoft.TeamFoundation.PowerShell,This is a PowerShell snap-in that includes the Team Foundation Server cmdlets."
"Version"="14.0.0.0"
"ApplicationBase"="C:\\Program Files (x86)\\Microsoft Team Foundation Server 2015 Power Tools"
"AssemblyName"="Microsoft.TeamFoundation.PowerTools.PowerShell, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
"ModuleName"="C:\\Program Files (x86)\\Microsoft Team Foundation Server 2015 Power Tools\\Microsoft.TeamFoundation.PowerTools.PowerShell.dll"
"CustomPSSnapInType"="Microsoft.TeamFoundation.PowerTools.PowerShell.TFPSSnapIn"

Double check AssemblyName, ApplicationBase, ModuleName and Version entries. Script above works with Microsoft Team Foundation Server 2015 Power Tools

回答1:

I am going to have a quick punt here and say it is probably something to do with 32-bit vs 64-bit powershell. If I run Add-PSSnapinicrosoft.TeamFoundation.PowerShell from normal 64-bit powershell fine. But if I run it from C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell_ise.exe I get the above exception. I am going to go ahead and say that the build server is a 32-bit application and there for starting a 32-bit runtime.

Not really sure what the fix is exactly but maybe the following will point you in the right direction.

PowerShell (2.0, 32-bit) can't load TFS 2010 snap-in... except when it can

https://social.msdn.microsoft.com/Forums/en-US/a116799a-0476-4c42-aa3e-45d8ba23739e/tfs-power-tools-2008-powershell-snapin-wont-run-in-on-64bit-in-windows-2008-r2?forum=tfspowertools



回答2:

I had this issue and to solve I notice that by default the cmdlets are not added during the PowerTools installation. You need to run a full install to make it work.

I posted here some pictures: https://fabiostawinski.wordpress.com/2016/07/11/the-windows-powershell-snap-in-microsoft-teamfoundation-powershell-is-not-installed-on-this-computer/