Skip to content

guitarrapc/UnityBuildRunner

Repository files navigation

dotnet-build release NuGet NuGet

UnityBuildRunner

This tool enable you stdout Unity Build log on windows, and control Timeout.

Note: Linux/macOS don't need use this tool, just pass -logfile - argument to see log on stdout.

Motivation

Windows Unity BatchBuild not provide Unity Build log standard output option. This small tool provide realtime stdout build log output and build timeout control.

Installation

You can install as .NET Global Tool or .NET Tool.

# install as global tool
dotnet tool install -g UnityBuildRunner

# install to project's .config
dotnet tool install UnityBuildRunner

Or, you can install as nuget package library.

Install-Package UnityBuildRunner.Core

Usage

CLI (Help)

You can run installed tool via UnityBuildRunner (.NET Global Tool) or dotnet UnityBuildRunner (.NET Tool) command.

$ UnityBuildRunner --help
Usage: UnityBuildRunner [options...]

Options:
  -unity-path, --unity-path <String>    Full Path to the Unity.exe (Leave empty when use 'UnityPath' Environment variables instead.) (Default: )
  -timeout, --timeout <String>          Timeout to terminate execution within. default: "00:60:00" (Default: 02:00:00)

Commands:
  help       Display help.
  version    Display version.

CLI (Basic)

All you need to do is pass unity's path as -u UnityPath and leave other argments as is.

Unity - Manual: Command line arguments

If you are running Unity batch build like this.

$ "C:\Program Files\Unity\Hub\Editor\2022.3.3f1\Editor\Unity.exe" -quit -batchmode -buildTarget "WindowsStoreApps" -projectPath "C:\git\MRTKSample\Unity" -logfile "log.log" -executeMethod "HoloToolkit.Unity.HoloToolkitCommands.BuildSLN"

Then, append UnityBuildRunner --unity-path <UnityPath> or dotnet UnityBuildRunner --unity-path <UnityPath> to existing command, that's all.

# .NET Global Tool
$ UnityBuildRunner --unity-path "C:\Program Files\Unity\Hub\Editor\2022.3.3f1\Editor\Unity.exe" -quit -batchmode -buildTarget "WindowsStoreApps" -projectPath "C:\git\MRTKSample\Unity" -logfile "log.log" -executeMethod "HoloToolkit.Unity.HoloToolkitCommands.BuildSLN"

# .NET Tool
$ dotnet UnityBuildRunner --unity-path "C:\Program Files\Unity\Hub\Editor\2022.3.3f1\Editor\Unity.exe" -quit -batchmode -buildTarget "WindowsStoreApps" -projectPath "C:\git\MRTKSample\Unity" -logfile "log.log" -executeMethod "HoloToolkit.Unity.HoloToolkitCommands.BuildSLN"

Note: Another way to specifying UnityPath is via Environment Variable UnityPath.

# Environment Variables
$ set UnityPath=C:\Program Files\Unity\Hub\Editor\2022.3.3f1\Editor\Unity.exe

# .NET Global Tool
$ UnityBuildRunner -quit -batchmode -buildTarget "WindowsStoreApps" -projectPath "C:\git\MRTKSample\Unity" -logfile "log.log" -executeMethod "HoloToolkit.Unity.HoloToolkitCommands.BuildSLN"

# .NET Tool
$ dotnet UnityBuildRunner -quit -batchmode -buildTarget "WindowsStoreApps" -projectPath "C:\git\MRTKSample\Unity" -logfile "log.log" -executeMethod "HoloToolkit.Unity.HoloToolkitCommands.BuildSLN"

Library (Basic)

You can use as Library as well. This is sample code to run Unity Build.

// Parse settings from argument
var settings = DefaultSettings.Parse(args, @"C:\Program Files\Unity\Hub\Editor\2022.3.3f1\Editor\Unity.exe", TimeSpan.FromMinutes(30));
using var cts = settings.CreateCancellationTokenSource();

// Run build
IBuilder builder = new DefaultBuilder(settings, logger);
await builder.BuildAsync(cts.Token);

// ExitCode is UnityBuildRunner and respect Unity's ExitCode.
Console.WriteLine(builder.ExitCode);

FAQ

What happen when passing -logFile - argument?

Unity.exe not generate log file when passing - as log file name. Therefore UnityBuildRunner replace - to temporary log file unitybuild.log instead.