Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bruno-garcia/860f8b61d857183989b989c869d777bb to your computer and use it in GitHub Desktop.
Save bruno-garcia/860f8b61d857183989b989c869d777bb to your computer and use it in GitHub Desktop.
msbuild task: wait for file to exist
<WaitFor FilePath="$(MSBuildProjectDirectory)/../../samples/unity-of-bugs/Library/ScriptAssemblies/UnityEngine.TestRunner.dll" Delay="5000" />
<UsingTask
TaskName="WaitFor"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup>
<FilePath ParameterType="System.String" Required="true" />
<Delay ParameterType="System.Int32" Required="true" />
</ParameterGroup>
<Task>
<Code Type="Fragment" Language="cs">
<![CDATA[
int iterations = 10;
var sleep = this.Delay / iterations;
var i = 0;
do
{
if (System.IO.File.Exists(this.FilePath))
{
return true;
}
Log.LogMessage($"Waiting ({i}x) {sleep}ms for {this.FilePath}.");
System.Threading.Thread.Sleep(sleep);
} while (++i < iterations);
Log.LogError($"Waited but couldn't find {this.FilePath}.");
]]>
</Code>
</Task>
</UsingTask>
@bruno-garcia
Copy link
Author

/Applications/Unity/Hub/Editor/2019.4.21f1/Unity.app/Contents/MacOS/Unity -quit -batchmode -nographics -logFile - -projectPath samples/unity-of-bugs -buildMacOS64Player game

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment