Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Error when building: "UnauthorizedAccessException: Access to the path 'LICENSE' is denied".

Discussion in 'Editor & General Support' started by unity_E9FfAw7RsMp7yg, Jul 10, 2022.

  1. unity_E9FfAw7RsMp7yg

    unity_E9FfAw7RsMp7yg

    Joined:
    Jan 13, 2020
    Posts:
    14
    My Unity project was building just fine until yesterday evening.
    This morning, without having done any changes to the project, I get the error mentioned in the title when trying to build. I have not done any changes to the filesystem (i.e. changed permissions or anything of the like). I also didn't install any new software. Basically, I didn't do anything of significance (that I know of) that would cause this error today, when yesterday evening I wasn't getting this error and building was working fine.

    I am getting this on Windows 11 and Unity 2021.3.3f1.180

    Here's the full output of the error:



    I am using a custom build pipeline, which basically does a "normal" build plus some postprocessing scripts. However, I also get this error when I use the normal Unity Build (i.e. through File -> Build Settings -> Build) The custom build pipeline looks as follows, and the last code that executes in this file is
    UnityEngine.Debug.Log("Build failed");
    in line 57:

    Code (CSharp):
    1.  
    2.  
    3. using System.Collections;
    4. using System.Collections.Generic;
    5. using UnityEngine;
    6. using UnityEditor;
    7. using UnityEditor.Build.Reporting;
    8. using System.IO;
    9. using System.IO.Compression;
    10. using System.Diagnostics;
    11. using System;
    12.  
    13. public class CustomBuildMenu
    14. {
    15.     public string password;
    16.     [MenuItem("File/Run Custom Build", false, 211)]
    17.     static void RunCustomBuild()
    18.     {
    19.         bool bPingSuccess = false;
    20.         Stopwatch stopWatch = new Stopwatch();
    21.         stopWatch.Start();
    22.         var ping = new Ping("192.168.101.129");
    23.         while (!(ping.isDone || stopWatch.Elapsed > TimeSpan.FromSeconds(10)))
    24.         {
    25.             bPingSuccess = ping.isDone;
    26.         }
    27.         ping.DestroyPing();
    28.         stopWatch.Stop();
    29.         UnityEngine.Debug.Log(string.Format("Ping completed with success: {0}", bPingSuccess));
    30.  
    31.         if (!bPingSuccess)
    32.         {
    33.             UnityEngine.Debug.Log("Aborting build. Could not ping remote mac. Is it running?");
    34.             return;
    35.         }
    36.         UnityEngine.Debug.Log("Ping to remote mac successful. Continuing build...");
    37.  
    38.         string password = EditorInputDialog.Show("Password", "Enter password for remote mac", "");
    39.         if (string.IsNullOrEmpty(password) || string.IsNullOrWhiteSpace(password))
    40.         {
    41.             return;
    42.         }
    43.  
    44.         BuildPlayerOptions buildPlayerOptions = GetCurrentBuildOptions();
    45.  
    46.         BuildReport report = BuildPipeline.BuildPlayer(buildPlayerOptions);
    47.         BuildSummary summary = report.summary;
    48.  
    49.         if (summary.result == BuildResult.Succeeded)
    50.         {
    51.             UnityEngine.Debug.Log("Build succeeded: " + summary.totalSize + " bytes");
    52.             PostProcess(report, password);
    53.         }
    54.  
    55.         if (summary.result == BuildResult.Failed)
    56.         {
    57.             UnityEngine.Debug.Log("Build failed");
    58.         }
    59.     }
    60.  
    61.     static BuildPlayerOptions GetCurrentBuildOptions(BuildPlayerOptions defaultOptions = new BuildPlayerOptions())
    62.     {
    63.         return BuildPlayerWindow.DefaultBuildMethods.GetBuildPlayerOptions(defaultOptions);
    64.     }
    65.  
    66.     static void PostProcess(BuildReport report, string password)
    67.     {
    68.         string sPath = @"C:\Users\chris\builds\game\ios\";
    69.         string sFile = @"C:\Users\chris\builds\game\iosBuild.zip";
    70.         if (File.Exists(sFile))
    71.         {
    72.             File.Delete(sFile);
    73.         }
    74.  
    75.  
    76.  
    77.         ZipFile.CreateFromDirectory(sPath, sFile); // something here is not working. Read docs for debug
    78.  
    79.         RunFile(@"C:\Users\chris\source\repos\game\PrePostBuildShellScripts", "@publishToMac.bat", password);
    80.  
    81.     }
    82.     static int RunFile(string directory, string file, string password)
    83.     {
    84.         int exitCode = -1;
    85.         try
    86.         {
    87.             ProcessStartInfo processInfo;
    88.             Process process;
    89.  
    90.             processInfo = new ProcessStartInfo();
    91.             processInfo.WorkingDirectory = directory;
    92.             processInfo.FileName = file;
    93.             processInfo.CreateNoWindow = false;
    94.             processInfo.UseShellExecute = true;
    95.             processInfo.Arguments = password;
    96.  
    97.             process = Process.Start(processInfo);
    98.             process.WaitForExit();
    99.             exitCode = process.ExitCode;
    100.             process.Close();
    101.         }
    102.         catch (Exception e)
    103.         {
    104.             UnityEngine.Debug.Log(e.Message);
    105.         }
    106.         return exitCode;
    107.     }
    108.  
    109. }
    110.  
     
  2. unity_E9FfAw7RsMp7yg

    unity_E9FfAw7RsMp7yg

    Joined:
    Jan 13, 2020
    Posts:
    14
    I am still getting this error :(
     
  3. unity_E9FfAw7RsMp7yg

    unity_E9FfAw7RsMp7yg

    Joined:
    Jan 13, 2020
    Posts:
    14
    For now, I seem to have fixed it. If anyone else comes across this error, what worked for me was deleting the folder to which I build, so that Unity doesn't ask whether it should append to it or replace it. I hope this keeps working. Seems like a bug to me though?