Search Unity

"Pre-delete" build path sent to BuildPipeline.BuildPlayer

Discussion in 'Testing & Automation' started by QFSW, Jun 17, 2020.

  1. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,858
    Is there any possible way to reliably delete the existing build when making a new build? e.g
    Code (CSharp):
    1.  
    2. string buildPath = ...;
    3.  
    4. /* Delete build contents at buildPath */
    5.  
    6. BuildPlayerOptions buildData = new BuildPlayerOptions
    7. {
    8.     target = ...,
    9.     targetGroup = ...,
    10.  
    11.     locationPathName = buildPath,
    12.     scenes = ...,
    13.     options = ...
    14. };
    15.  
    16. BuildPipeline.BuildPlayer(buildData);
    I thought of doing the following, but it doesn't work for targets like Windows that create extra files around the path

    Code (CSharp):
    1. if (!File.Exists(buildPath))
    2. {
    3.     File.Delete(buildPath);
    4. }
    5.  
    6. if (Directory.Exists(buildPath))
    7. {
    8.     Directory.Delete(buildPath, true);
    9. }
    I can't delete the "containing" folder either as that may contain other files that aren't build artifacts

    Any ideas on what would be the most robust and reliable way to do this? One of the motivations for this is how you cannot ovewrite a mono build with an IL2CPP build directly without errors ocurring.

    Thanks!
     
  2. WolveX

    WolveX

    Joined:
    May 31, 2016
    Posts:
    45
    Hi,
    if you are using a CI/CD solution you can add a separate step before start the build for clearing the target path, I use the following cmd command in TeamCity:

    Code (CSharp):
    1. rm -R -f ./*
    This will silently delete everything in the "Builds" directory
    Here is a screenshot of the step in TeamCity

    upload_2020-6-17_23-43-54.png

    Hope this helps!
     
    QFSW likes this.
  3. QFSW

    QFSW

    Joined:
    Mar 24, 2015
    Posts:
    2,858
    I would be able to do the following from C#, but cannot for these reasons

    The path can be selected by the end user, so if they decided to use say, Desktop, and I wiped that. Let's say the result would be catastrophic, so since I don't force a build folder I can't assume that I can wipe a folder like that
     
unityunity