Dinomite-Studios / unity-azure-pipelines-tasks

Azure DevOps extension adding tools to build and deploy Unity 3D projects using Azure Pipelines
https://unitydevops.com/
MIT License
121 stars 49 forks source link

Building iOS on MacOS MS-hosted machine #247

Open Stephan-DXRS opened 10 months ago

Stephan-DXRS commented 10 months ago

We're trying to build our Unity iOS app, but are running into an issue. We are using the UnitySetup task, which works great on a Windows MS-hosted machine. However, on MacOS it keeps complaining about not finding the Unity Hub executable.

After digging into the code, we found the following couple of lines:

// Setup and read inputs.
let unityHubExecutablePath = tl.getPathInput(customUnityHubPathInputVariableName);
if (!unityHubExecutablePath) {
    // TODO: Add default paths for macOS / Linux.
    unityHubExecutablePath = 'C:\\Program Files\\Unity Hub\\Unity Hub.exe';
}

We tried setting customUnityHubPath to /Applications/Unity Hub.app as this is the default location for Unity Hub on MacOS. But the pipeline fails: "Unable to locate executable file". If we understand correctly, the UnitySetup task expects Unity Hub to be installed on the machine and it's not installed on the MacOS images of Microsoft.

Is there a way (task) to download and install Unity Hub via a seperate task? We've looked into the unitysetup.powershell module, but this only lets you install the Unity Editor.

Thank you in advance.

Risu-swift commented 9 months ago
 - task: PowerShell@2
    displayName: 'Install Unity Hub'
    inputs:
      targetType: 'inline'
      script: |

        # Define the Unity Hub download URL for macOS
        $unityHubUrl = "https://public-cdn.cloud.unity3d.com/hub/prod/UnityHubSetup.dmg"

        # Define the default Applications directory
        $applicationsDir = "/Applications"

        # Download Unity Hub
        Invoke-WebRequest -Uri $unityHubUrl -OutFile "$PSScriptRoot/UnityHubSetup.dmg"

        # Mount the DMG file using hdiutil
        hdiutil attach "$PSScriptRoot/UnityHubSetup.dmg" -nobrowse -mountpoint "$PSScriptRoot/MountedImage"

        # Copy Unity Hub to the default Applications directory
        Copy-Item -Path "$PSScriptRoot/MountedImage/Unity Hub.app" -Destination $applicationsDir -Recurse

        chmod +x "$applicationsDir/Unity Hub.app/Contents/MacOS/Unity Hub"

        # Unmount the DMG file
        hdiutil detach "$PSScriptRoot/MountedImage"

        # Print the installation directory
        Write-Host "Unity Hub installed to: $applicationsDir/Unity Hub.app"

  - task: UnitySetupTask@1
    inputs:
      versionSelectionMode: 'project'
      installIOSModule: true
      customUnityHubPath: /Applications/Unity Hub.app/Contents/MacOS/Unity Hub

I used this code snippet to download and setup Unity hub on a MacOS agent. I am not sure if there is any other better way to do this but this works