Creating Your First Installer
Once WiX is set up, creating our first installer is only a few clicks away. We have a few options for this.
1. Enabling automatic creation of installation packages
If you head over to the WiX Settings in the Project settings window. You'll see the option to 'Automatically Create Installer on Build'. Enabling this, will generate an installer every time you do a build in Unity.
2. Integration into your own build pipeline
The option above creates an installer using the Postbuild script Editor/Build/Scripts/WiXPostBuild.cs
which automates the installer creation by integrating into the Unity build pipeline. You might not want to create an installer every time you do a build though and might even have your own code for release builds set up. In that case, feel free to use the default script as a reference. Creating an installer from code is as simple as calling WiX.CreateInstaller(report);
where 'report' is a BuildReport object that Unity passes to scripts implementing the IPostprocessBuildWithReport interface. A complete sample might look like this:
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
public class MyCustomBuildProcessor : IPostprocessBuildWithReport {
public int callbackOrder { get { return 0; } }
public void OnPostprocessBuild(BuildReport report) {
if (!WiX.IsPlatformSupported) {
return;
}
if (report.summary.platform != BuildTarget.StandaloneWindows &&
report.summary.platform != BuildTarget.StandaloneWindows64) {
return;
}
WiX.CreateInstaller(report);
}
}
3. Manually creating the installer from an existing build
(Not recommended)
Creating an installation package for an existing build can be done in the Advanced
section in the WiX for Unity Wizard and click on Create installer for existing build
. It will prompt you to select the folder of your Unity build. Next, it will prompt you to choose a name for your installation package (.msi file). After you hit Save
, the installer will be generated.
The reason creating installers from existing builds is not optimal, is that the installer creation uses info from your Unity project settings (most notably the installers UpgradeCode, but also the Application.version
), to create the installer. It would be easy to make a mistake like creating an installer with the wrong version for a past build.
So it is recommended to create installers using Unitys BuildPipeline instead.