title: Unity's IPreprocessBuildWithReport.OnPreprocessBuild throws an error
body: <p>I got a tiny script that creates a text file in Resources folder before building that needs to be included in the build. So I wrote this script using Unity's <a href="https://docs.unity3d.com/2018.1/Documentation/ScriptReference/Build.IPreprocessBuildWithReport.OnPreprocessBuild.html" rel="nofollow noreferrer">IPreprocessBuildWithReport</a>:</p>
  
  <pre><code>using UnityEngine;
  using UnityEditor;
  using UnityEditor.Build;
  using System.IO;
  
  class MyCustomBuildProcessor : IPreprocessBuildWithReport
  {
      public int callbackOrder { get { return 0; } }
      public void OnPreprocessBuild(UnityEditor.Build.Reporting.BuildReport report)
      {
          File.WriteAllText(
              Application.dataPath + "/Resources/version.txt",
              string.Format("{0}", PlayerSettings.Android.bundleVersionCode));
  
          AssetDatabase.Refresh();
      }
  }
  </code></pre>
  
  <p>Note the <code>AssetDatabase.Refresh();</code> statement at the end. It makes sure Unity becomes aware of the change and includes the updated file in the build. Now, whenever time I change the <code>bundleVersionCode</code> and press build, Unity updates the file as expected but the build fails with this pretty generic error:</p>
  
  <p><a href="https://i.stack.imgur.com/KkC5o.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KkC5o.jpg" alt="enter image description here"></a></p>
  
  <p>However, if I try to build the second time with the same <code>bundleVersionCode</code> than no file changes occur and the build succeeds.</p>
  
  <p>So I guess the <code>AssetDatabase.Refresh()</code> doesn't really work in <code>OnPreprocessBuild()</code>, or am I doing something obviously stupid again? Can anyone suggest a workaround?</p>
  
  <p><strong>EDIT:</strong>
  Please ignore the first two errors, just Unity doesn't like me when I'm excluding files from build by the <code>~</code> postfix.</p>