Created
May 13, 2021 23:16
-
-
Save bruno-garcia/860f8b61d857183989b989c869d777bb to your computer and use it in GitHub Desktop.
msbuild task: wait for file to exist
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
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/Applications/Unity/Hub/Editor/2019.4.21f1/Unity.app/Contents/MacOS/Unity -quit -batchmode -nographics -logFile - -projectPath samples/unity-of-bugs -buildMacOS64Player game