Search Unity

Help trying to replace files PreBuild

Discussion in 'Unity Build Automation' started by Uli_Okm, Feb 28, 2019.

  1. Uli_Okm

    Uli_Okm

    Joined:
    Jul 10, 2012
    Posts:
    95
    Hello, I am currently trying to setup a way to replace files in project without breaking links in editor.
    I am trying to run this in the prebuild function

    Code (CSharp):
    1. System.IO.File.Replace(string.Format(Application.dataPath + "/ClientSettings/{0}/icon.png", targetFolder), Application.dataPath + "/ClientSettings/current/icon.png", Application.dataPath + "/ClientSettings/current/bkp_icon.png");
    2.             System.IO.File.Replace(string.Format(Application.dataPath + "/ClientSettings/{0}/splash.png", targetFolder), Application.dataPath + "/ClientSettings/current/splash.png", Application.dataPath + "/ClientSettings/current/bkp_splash.png");
    3.             System.IO.File.Replace(Application.dataPath + "/ClientSettings/current/logo.png", string.Format(Application.dataPath + "/ClientSettings/{0}/logo.png", targetFolder), Application.dataPath + "/ClientSettings/current/bkp_logo.png");
    4.  
    5.             //FileUtil.ReplaceFile(string.Format("Assets/ClientSettings/{0}/icon.png", targetFolder), "Assets/ClientSettings/current/icon.png");
    6.             //FileUtil.ReplaceFile(string.Format("Assets/ClientSettings/{0}/splash.png", targetFolder), "Assets/ClientSettings/current/splash.png");
    7.             //FileUtil.ReplaceFile(string.Format("Assets/ClientSettings/{0}/logo.png", targetFolder), "Assets/ClientSettings/current/logo.png");
    8.             AssetDatabase.Refresh();
    I also tried the commented methods above.
    The "ClientSettings/current/icon.png" is the icon that is currently set in the editor as default icon, so replacing it with files from another folder (same name) would simply replace the contents without breaking the editor links.
    I tested in my local editor and this works as expected. But in cloud build, no error occurs but in the end the files aren`t replaced.
    Can anyone give a direction about how to fix this?
    (One important point: Setting icons and splash images trhough their functions in ApplicationSettings wouldn`t work because i also need to replace this "logo.png" image)
    Thanks
     
  2. Uli_Okm

    Uli_Okm

    Joined:
    Jul 10, 2012
    Posts:
    95
    Just in case somebody may find this and feel lost:
    Actually the problem wasn't in this specific bit of code.
    Before that I was trying to set "PlayerSettings.bundleVersion" with a string value (1.0.xx). The Full Log in Cloud Build WASN'T showing any error about this, but this was actually stopping the code execution