Created
January 6, 2015 15:32
-
-
Save fearthecowboy/ccd5e0694d508900ebf9 to your computer and use it in GitHub Desktop.
Super Simple PowerShell task for MSBuild.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<!-- @FearTheCowboy's Simple PowerShell Task for MSBuild --> | |
<UsingTask TaskName="PowerShell" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll"> | |
<ParameterGroup><ScriptBlock ParameterType="System.String" Required="true" /></ParameterGroup> | |
<Task><Reference Include="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll"/><Code Type="Class" Language="cs"><![CDATA[ | |
public class PowerShell : Microsoft.Build.Tasks.Exec { | |
public string ScriptBlock {set { EchoOff=true; Command = string.Format( "@powershell \"Invoke-Command -ScriptBlock {{ $errorActionPreference='Stop'; {0} ; exit $LASTEXITCODE }} \"", value.Replace("\"","\"\"").Replace("\r\n",";").Replace("\n",";").Replace("\r",";")); } } | |
}]]></Code></Task> | |
</UsingTask> | |
<PropertyGroup> | |
<MyTestScript> | |
$foo = 'Hello There' | |
echo "$foo - script dir : $(MSBuildThisFileDirectory)" | |
</MyTestScript> | |
</PropertyGroup> | |
<Target Name="Build"> | |
<PowerShell ScriptBlock="$(MyTestScript)" /> | |
</Target> | |
</Project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍 Thanx!!!