Created
September 2, 2015 13:12
-
-
Save palpha/d303d4aa1e4a51af5b47 to your computer and use it in GitHub Desktop.
Simple inline PowerShell task for MSBuild 14
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
<UsingTask TaskName="PowerShell" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"> | |
<ParameterGroup> | |
<ScriptBlock ParameterType="System.String" Required="true" /> | |
<ScriptParams ParameterType="System.String" Required="false" /> | |
</ParameterGroup> | |
<Task> | |
<Reference Include="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"/> | |
<Code Type="Class" Language="cs"><![CDATA[ | |
public class PowerShell : Microsoft.Build.Tasks.Exec { | |
public string ScriptParams { | |
set { | |
Command = Command + " " + value; | |
} | |
} | |
public string ScriptBlock { | |
set { | |
EchoOff = true; | |
var tmp = System.IO.Path.GetTempFileName(); | |
try { | |
System.IO.File.WriteAllText(tmp, value); | |
System.IO.File.Move(tmp, tmp + ".ps1"); | |
Command = string.Format( "@powershell -NoProfile -NoLogo -File {0}", tmp + ".ps1" ); | |
} finally { | |
System.IO.File.Delete(tmp + ".ps1"); | |
} | |
} | |
} | |
}]]> | |
</Code> | |
</Task> | |
</UsingTask> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment