Created
October 23, 2014 12:16
-
-
Save sixeyed/bef61485f933b0e80b86 to your computer and use it in GitHub Desktop.
ExecAsync - simple inline MSBuild task for executing commands asynchronously
This file contains hidden or 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="ExecAsync" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" > | |
<ParameterGroup> | |
<exePath ParameterType="System.String" Required="true" /> | |
<arguments ParameterType="System.String" Required="true" /> | |
<waitMilliseconds ParameterType="System.Int32" Required="true" /> | |
</ParameterGroup> | |
<Task> | |
<Using Namespace="System.Diagnostics"/> | |
<Using Namespace="System.Threading"/> | |
<Code Type="Fragment" Language="cs"> | |
Log.LogMessage("Executing: " + exePath + arguments, MessageImportance.High); | |
ProcessStartInfo psi = new ProcessStartInfo(exePath); | |
psi.Arguments = arguments; | |
Process.Start(psi); | |
if (waitMilliseconds > 0) | |
{ | |
Log.LogMessage("Waiting for: " + waitMilliseconds.ToString() + "ms", MessageImportance.High); | |
Thread.Sleep(waitMilliseconds); | |
} | |
</Code> | |
</Task> | |
</UsingTask> | |
This file contains hidden or 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
<!-- TODO - include UsingTask for ExecAsync --> | |
<PropertyGroup> | |
<OSqlExePath>$(ProgramW6432)\Microsoft SQL Server\110\Tools\Binn\osql.exe</OSqlExePath> | |
</PropertyGroup> | |
<Target Name="DeployDatabase"> | |
<ExecAsync exePath='"$(OSqlExePath)"' | |
arguments=' -E -i "$(MSBuildThisFileDirectory)\Scripts\CREATE-database.sql"' | |
waitMilliseconds='500'/> | |
<!-- the next task will start after 0.5 seconds, while the SQL script will carry on running --> | |
</Target> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment