Skip to content

Instantly share code, notes, and snippets.

@sixeyed
Created October 23, 2014 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sixeyed/bef61485f933b0e80b86 to your computer and use it in GitHub Desktop.
Save sixeyed/bef61485f933b0e80b86 to your computer and use it in GitHub Desktop.
ExecAsync - simple inline MSBuild task for executing commands asynchronously
<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>
<!-- 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