Porting Unity Engine exe to UWP
Introduction
This solution aims to quickly and efficiently introduce a developed Unity desktop game/application (.exe) into the Windows ecosystem. The core principle is not to modify the original code and logic of the Unity application, but to perform a "containerized" encapsulation using MSIX packaging technology. This enables it to run on Windows 10/11 and be distributed via the Microsoft Store or other channels.
Porting Process Flowchart
SDK Integration and Unity Build
This stage is fundamental, ensuring the game's core functionality is complete.
SDK Integration
Within the Unity project, follow the standard SDK integration guide to complete tasks such as plugin import, API calls, and configuration settings. Be sure to complete all SDK-related development and testing during this stage.
Windows Platform Build:
In the Unity Editor, open File > Build Settings.
Select "PC, Mac & Linux Standalone" and set the target platform to "Windows".
Click "Build" to generate an output directory containing the .exe, _Data, and all other dependency files. This directory is the target we will package.
Handling Sandbox Compatibility
The MSIX sandbox environment restricts certain operations that are typically available by default in Win32, such as accessing the registry or system file directories.
- File System Access: Applications might attempt to write data to protected paths like
C:\Program Filesor the installation directory, which will fail. Data needs to be written to theWindows.Storage.ApplicationData.Current.LocalFolderpath (corresponding to%USERPROFILE%\AppData\Local\Packages\[PackageName]\LocalState). - Registry Access: Applications might read/write to
HKEY_LOCAL_MACHINEorHKEY_CURRENT_USER\Software\[Some global settings]. These write operations are redirected to a virtualized area. The program should be guided to store settings inHKEY_CURRENT_USER\Software\Classes\Local Settings\Software\[Application Name]. - Inter-process Communication (IPC): Complex IPC might be blocked; ensure the communication method works within the sandbox.
- Testing and Debugging: Conduct thorough testing to verify that all SDK functionalities behave identically in the MSIX-installed version compared to the traditional exe version.
Build, Test, and Distribute
- Generate MSIX Package: Use MSIX packaging technology to generate the Microsoft Store app package in
.msixformat. - Local Testing: Install the MSIX package and perform comprehensive functional testing.
- Run WACK: Use the Windows App Certification Kit to certify the package, resolving any compatibility issues.
- Store Submission: Submit the certified MSIX package to Microsoft Partner Center to complete the store listing process.
Note: Please set your local computer to Developer Mode, otherwise UWP applications cannot be installed properly.