0

I'm trying to run a powershell script when doing a file system publish for my project in Visual Studio, but snap-ins don't seem to be working when actually running the publish.

If I run the powershell script manually outside of visual studio the snap-in works fine, but when its executed via the publish it doesn't work.

Here is the target in the .pubxml profile.

<Target Name="Test" AfterTargets="GatherAllFilesToPublish">
    <Message Text="********************************** Test ***********************************" Importance="high" />
    <Exec Command="powershell.exe -file &quot;$(ProjectDir)\Properties\PublishProfiles\test.ps1&quot; $(ProjectDir)"/>
</Target>

And here is the powershell script

Add-PSSnapin Microsoft.TeamFoundation.PowerShell
$changeset = Get-TfsItemHistory $filePath -Recurse -StopAfter 1 | Select -ExpandProperty ChangesetId

Which results in

Add-PSSnapin : The Windows PowerShell snap-in 'Microsoft.TeamFoundation.PowerShell' is not installed on this computer.

Im also open to not using a snap-in if a alternative exists for the Get-TfsItemHistory command.

SikhWarrior
  • 947
  • 3
  • 18
  • 33

1 Answers1

0

I have no personal experience of this snap-in myself but here are some thoughts at least:

  • This might be a 32bit vs 64bit compatibility issue, if it works from a separate command prompt and not from inside the publish operation. Could the reason be they are running different versions?
  • Check what snap-ins are available by running Get-PSSnapin in the publish. Most likely it's not there but you can add it using the installutil.exe command.
    • See example 3 from this page
kim
  • 3,066
  • 2
  • 11
  • 20