Cake.Unity3D 0.7.0

Unity3D build support for Cake - https://github.com/samoatesgames/Cake.Unity3D

There is a newer version of this package available.
See the version list below for details.
Install-Package Cake.Unity3D -Version 0.7.0
dotnet add package Cake.Unity3D --version 0.7.0
<PackageReference Include="Cake.Unity3D" Version="0.7.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Cake.Unity3D --version 0.7.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Cake.Unity3D, 0.7.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Cake.Unity3D as a Cake Addin
#addin nuget:?package=Cake.Unity3D&version=0.7.0

// Install Cake.Unity3D as a Cake Tool
#tool nuget:?package=Cake.Unity3D&version=0.7.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Cake.Unity3D

About

Unity3D build support for Cake (https://github.com/cake-build/cake).

GitHub Nuget

Methods

/// <summary>
/// Build a provided Unity3D project with the specified build options.
/// </summary>
/// <param name="context">The active cake context.</param>
/// <param name="projectFolder">The absolute path to the Unity3D project to build.</param>
/// <param name="options">The build options to use when building the project.</param>
public static void BuildUnity3DProject(this ICakeContext context, FilePath projectFolder, Unity3DBuildOptions options)
/// <summary>
/// Test a provided Unity3D project with the specified test options.
/// </summary>
/// <param name="context">The active cake context.</param>
/// <param name="projectFolder">The absolute path to the Unity3D project to test.</param>
/// <param name="options">The test options to use when testing the project.</param>
public static void TestUnity3DProject(this ICakeContext context, FilePath projectFolder, Unity3DTestOptions options)
/// <summary>
/// Locate all installed version of Unity3D.
/// Warning: This currently only works for Windows and has only been tested on Windows 10.
/// </summary>
/// <param name="context">The active cake context.</param>
/// <returns>A dictionary containing 'key' Unity version, 'value' absolute install path</returns>
public static Dictionary<string, string> GetAllUnityInstalls(this ICakeContext context)
/// <summary>
/// Try and get the absolute install path for a specific Unity3D version.
/// </summary>
/// <param name="context">The active cake context.</param>
/// <param name="version">The version to try and locate.</param>
/// <param name="installPath">If found the absolute install path will be written to this out variable</param>
/// <returns>True if the editor version was found, false otherwise.</returns>
public static bool TryGetUnityInstall(this ICakeContext context, string version, out string installPath)
/// <summary>
/// Try and get the version of Unity3D a specified project uses.
/// </summary>
/// <param name="context">The active cake context.</param>
/// <param name="projectPath">The absolute path to the Unity3D project we want to get the Unity3D version for.</param>
/// <param name="unityVersion">If found the name of the Unity3D version used for the project.</param>
/// <returns>True if the editor version was found, false otherwise.</returns>
public static bool TryGetUnityVersionForProject(this ICakeContext context, string projectPath, out string unityVersion)

Example

Building a Project
#addin nuget:?package=Cake.Unity3D

var target = Argument("target", "Build");

Task("Build")
  .Does(() =>
{
	// Presuming the build.cake file is within the Unity3D project folder.
	var projectPath = System.IO.Path.GetFullPath("./");
	
	// The location we want the build application to go
	var outputPath = System.IO.Path.Combine(projectPath, "_build", "x64", "example.exe");
	
	// Get the version of Unity used by the Unity project
	string unityEditorVersion;
	if (!TryGetUnityVersionForProject(projectPath, out unityEditorVersion))
	{
		Error($"Failed to find Unity version for the project '{projectPath}'");
		return;
	}
	
	// Get the absolute path to the Unity3D editor.
	string unityEditorLocation;
	if (!TryGetUnityInstall(unityEditorVersion, out unityEditorLocation)) 
	{
		Error($"Failed to find '{unityEditorVersion}' install location");
		return;
	}
	
	// Create our build options.
	var options = new Unity3DBuildOptions()
	{
		Platform = Unity3DBuildPlatform.StandaloneWindows64,
		OutputPath = outputPath,
		UnityEditorLocation = unityEditorLocation,
		ForceScriptInstall = true,
		BuildVersion = "1.0.0"
	};
	
	// Perform the Unity3d build.
	BuildUnity3DProject(projectPath, options);
});

RunTarget(target);
Testing a Project
#addin nuget:?package=Cake.Unity3D

var target = Argument("target", "Test");

Task("Test")
  .Does(() =>
{
	// Presuming the build.cake file is within the Unity3D project folder.
	var projectPath = System.IO.Path.GetFullPath("./");
	
	// The location we want the test results to be output to (if this isn't specified the file will be output to 'test_results.xml' in the root Unity Project folder)
	var testResultsOutputPath = System.IO.Path.Combine(projectPath, "_test_results.xml");
	
	// Get the version of Unity used by the Unity project
	string unityEditorVersion;
	if (!TryGetUnityVersionForProject(projectPath, out unityEditorVersion))
	{
		Error($"Failed to find Unity version for the project '{projectPath}'");
		return;
	}
	
	// Get the absolute path to the Unity3D editor.
	string unityEditorLocation;
	if (!TryGetUnityInstall(unityEditorVersion, out unityEditorLocation)) 
	{
		Error($"Failed to find '{unityEditorVersion}' install location");
		return;
	}
	
	// Create our test options.
	var options = new Unity3DTestOptions()
	{
		TestMode = Unity3DTestMode.EditMode,
		TestResultOutputPath = testResultsOutputPath,
		UnityEditorLocation = unityEditorLocation
	};
	
	// Perform the Unity3d test.
	TestUnity3DProject(projectPath, options);
});

RunTarget(target);

Supported Platforms

Executing Platforms

Currently the addon only works on Windows and has only been tested on Windows 10. This is due to how the 'TryGetUnityInstall' works. What it does is look at all shortcuts in your Windows start menu and locate the Unity3D installs from that. In theory, if you just set the 'UnityEditorLocation' build option to the absolute path to your Unity3D install on Mac or Linux, this should also work.

Build Platforms

  • StandaloneWindows64
  • StandaloneWindows
  • WebGL

In theory, all platforms that the executing platform supports should work. However, I haven't test any apart from the above list.

Cake.Unity3D

About

Unity3D build support for Cake (https://github.com/cake-build/cake).

GitHub Nuget

Methods

/// <summary>
/// Build a provided Unity3D project with the specified build options.
/// </summary>
/// <param name="context">The active cake context.</param>
/// <param name="projectFolder">The absolute path to the Unity3D project to build.</param>
/// <param name="options">The build options to use when building the project.</param>
public static void BuildUnity3DProject(this ICakeContext context, FilePath projectFolder, Unity3DBuildOptions options)
/// <summary>
/// Test a provided Unity3D project with the specified test options.
/// </summary>
/// <param name="context">The active cake context.</param>
/// <param name="projectFolder">The absolute path to the Unity3D project to test.</param>
/// <param name="options">The test options to use when testing the project.</param>
public static void TestUnity3DProject(this ICakeContext context, FilePath projectFolder, Unity3DTestOptions options)
/// <summary>
/// Locate all installed version of Unity3D.
/// Warning: This currently only works for Windows and has only been tested on Windows 10.
/// </summary>
/// <param name="context">The active cake context.</param>
/// <returns>A dictionary containing 'key' Unity version, 'value' absolute install path</returns>
public static Dictionary<string, string> GetAllUnityInstalls(this ICakeContext context)
/// <summary>
/// Try and get the absolute install path for a specific Unity3D version.
/// </summary>
/// <param name="context">The active cake context.</param>
/// <param name="version">The version to try and locate.</param>
/// <param name="installPath">If found the absolute install path will be written to this out variable</param>
/// <returns>True if the editor version was found, false otherwise.</returns>
public static bool TryGetUnityInstall(this ICakeContext context, string version, out string installPath)
/// <summary>
/// Try and get the version of Unity3D a specified project uses.
/// </summary>
/// <param name="context">The active cake context.</param>
/// <param name="projectPath">The absolute path to the Unity3D project we want to get the Unity3D version for.</param>
/// <param name="unityVersion">If found the name of the Unity3D version used for the project.</param>
/// <returns>True if the editor version was found, false otherwise.</returns>
public static bool TryGetUnityVersionForProject(this ICakeContext context, string projectPath, out string unityVersion)

Example

Building a Project
#addin nuget:?package=Cake.Unity3D

var target = Argument("target", "Build");

Task("Build")
  .Does(() =>
{
	// Presuming the build.cake file is within the Unity3D project folder.
	var projectPath = System.IO.Path.GetFullPath("./");
	
	// The location we want the build application to go
	var outputPath = System.IO.Path.Combine(projectPath, "_build", "x64", "example.exe");
	
	// Get the version of Unity used by the Unity project
	string unityEditorVersion;
	if (!TryGetUnityVersionForProject(projectPath, out unityEditorVersion))
	{
		Error($"Failed to find Unity version for the project '{projectPath}'");
		return;
	}
	
	// Get the absolute path to the Unity3D editor.
	string unityEditorLocation;
	if (!TryGetUnityInstall(unityEditorVersion, out unityEditorLocation)) 
	{
		Error($"Failed to find '{unityEditorVersion}' install location");
		return;
	}
	
	// Create our build options.
	var options = new Unity3DBuildOptions()
	{
		Platform = Unity3DBuildPlatform.StandaloneWindows64,
		OutputPath = outputPath,
		UnityEditorLocation = unityEditorLocation,
		ForceScriptInstall = true,
		BuildVersion = "1.0.0"
	};
	
	// Perform the Unity3d build.
	BuildUnity3DProject(projectPath, options);
});

RunTarget(target);
Testing a Project
#addin nuget:?package=Cake.Unity3D

var target = Argument("target", "Test");

Task("Test")
  .Does(() =>
{
	// Presuming the build.cake file is within the Unity3D project folder.
	var projectPath = System.IO.Path.GetFullPath("./");
	
	// The location we want the test results to be output to (if this isn't specified the file will be output to 'test_results.xml' in the root Unity Project folder)
	var testResultsOutputPath = System.IO.Path.Combine(projectPath, "_test_results.xml");
	
	// Get the version of Unity used by the Unity project
	string unityEditorVersion;
	if (!TryGetUnityVersionForProject(projectPath, out unityEditorVersion))
	{
		Error($"Failed to find Unity version for the project '{projectPath}'");
		return;
	}
	
	// Get the absolute path to the Unity3D editor.
	string unityEditorLocation;
	if (!TryGetUnityInstall(unityEditorVersion, out unityEditorLocation)) 
	{
		Error($"Failed to find '{unityEditorVersion}' install location");
		return;
	}
	
	// Create our test options.
	var options = new Unity3DTestOptions()
	{
		TestMode = Unity3DTestMode.EditMode,
		TestResultOutputPath = testResultsOutputPath,
		UnityEditorLocation = unityEditorLocation
	};
	
	// Perform the Unity3d test.
	TestUnity3DProject(projectPath, options);
});

RunTarget(target);

Supported Platforms

Executing Platforms

Currently the addon only works on Windows and has only been tested on Windows 10. This is due to how the 'TryGetUnityInstall' works. What it does is look at all shortcuts in your Windows start menu and locate the Unity3D installs from that. In theory, if you just set the 'UnityEditorLocation' build option to the absolute path to your Unity3D install on Mac or Linux, this should also work.

Build Platforms

  • StandaloneWindows64
  • StandaloneWindows
  • WebGL

In theory, all platforms that the executing platform supports should work. However, I haven't test any apart from the above list.

Dependencies

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
0.8.0 3,194 5/2/2020
0.7.0 536 12/24/2019
0.6.0 233 12/23/2019
0.5.0 913 5/14/2019
0.4.0 1,540 5/6/2018
0.3.1 626 5/6/2018
0.3.0 646 5/5/2018
0.2.0 558 5/3/2018
0.1.0 537 5/2/2018