Calling PowerShell from MSBuild

Someone has already done the hard work to write an MSBuild task that allows you to call PowerShell scripts a bit like this :

<UsingTask 
      AssemblyFile="PowershellMSBuildTask.dll"
      TaskName="PowerShell" />

<PropertyGroup>
   <ReplaceScript>
      <![CDATA[get-content "..." | % { $_.Replace("something", "something else") } | set-content "..."]]>
   </ReplaceScript>
</PropertyGroup>

<Target Name="AfterGet">
   <Powershell Script="$(ReplaceScript)/>"
</Target>
3 Comments Filed Under [ .Net ]

Comments

# re: Calling PowerShell from MSBuild
Gravatar Nice find! That's going to save building assemblies for trivial little tasks.
Left by Daniel Gray on 10/6/2008 8:55 PM
# re: Calling PowerShell from MSBuild
Gravatar is there any way to call the .ps1 file....
Left by Sahas on 7/21/2009 7:57 PM
# re: Calling PowerShell from MSBuild
Gravatar Thank you but moving the code from pure powershell to cmdlet is really just performance/convenience optimization. I am interested in steps/code as well as gotchas for using the Microsoft.Build.BuildEngine directly. I can move the actual impl between ps1 and cmdlet fairly easily. – Milan Gardian Jan 23 '09 at 15:10
I have msbuild scripts in many different places, and I was wanting to be able to run something from one central place. If you end up with a working answer, I'd love to see a blog post or something
Left by gioca al Poker online su Interne on 3/19/2010 11:02 AM

Leave Your Comment

Title*
Name*
Email (never displayed)
 (will show your gravatar)
Url
Comment*

Please add 3 and 6 and type the answer here:

Preview Your Comment.