Unity Cloud Build with custom .dll files

Recently I was wondering how to approach the process of building my project in Unity Cloud Build service (from now on I’ll use UCB for short). Usually it’s a simple task: you go to UCB site, setup your  project, attach repository and you’re good to go, but what if your project consists of custom build .dll files that requires rebuilding for each platform? As you know UCB does not support msbuild to perform this task in the cloud so it has to be done before updating your repository… for each platform you are targeting.

I wanted to make it as simple as possible and fully automatic so I won’t have to spend more than just a few seconds each time I want to prepare build for all target platforms.

The approach

I’ve decided to have a specific branch on my git repository for a single build target ( for my purpose at the time I was working on it I only needed iOS and Standalone builds ) that will be updated with the current master, rebuild .dlls and push changes to the branch. The UCB will then automatically start build of the Unity project  for each target and as a pre-build action: build asset bundles that are included in streaming assets as well.

Automatization

First I’ve created these new branches for iOS and Standalone versions. Then I’ve configured UCB for these two projecsts ( you can find tutorials how to configure UCB here). Make sure you have auto-build option enabled if you want builds to be performed automatically when your repository gets updated.

One additional thing I had to change was the asset bundles build tools. My tools were also included in dlls like the rest of the scripts, however in order to build asset bundles in the cloud I had to move it in the standard Editor folder. I didn’t want to rewrite them or get rid of them so I didn’t use the UCB functionality to build bundles but used the Pre-Export Method to call my tool. Each build target just before build calls this method, the bundles gets builded and placed into streaming assets folder.

The last thing was writing the scripts to automate the process: from updating branches to building and pushing changes to UCB. I’ve split this functionality into several files: for each single target, building all targets at once and the core script that will be shared for each build.

This is how the core file looked like:

git reset --hard
git checkout %1
git fetch origin
git merge origin/dev
"C:/Program Files (x86)/MSBuild/14.0/bin/amd64/MSBuild.exe" /verbosity:q /property:Configuration=%2 Solution.sln
git add *
git commit -m %3
git push origin

First the git repository gets reset so no changes are present, then the branch is checked out (the name is the first parameter after the filename when executing this script). Then the changes are fetched and merged (pull) and at this point the target repository is up-to-date with the dev on which I’m working on. Next the msbuild is executed for specific configuration  (the target platform passed as the second parameter). Then all the changes are added and commited with the specific name as the third parameter and pushed. At that point the repo is updated with up to date changes and dlls are rebuilded. As soon as the UCB notify those changes the build for that target will be started.

Each build target script has similar structure:

echo Preparing Standalone build
call "Build Version.bat" standalone ReleaseStandalone "Auto-build"

As you can see I’m calling the script that was presented earlier with parameters: branch target and commit message.

If I want to build all versions of the game in one go I’m just calling the same Build Version script with different parameters.

Final thoughs

When you work with custom dll files in Unity it would be ideal to have a dedicated build machine that could run the building process using jenkins or any other automatic build solution from the very start (fetching the changes) to the end (pushing even the game to appstore or google play), but if you’re a small developer utilizing Unity Cloud Build service can be also a viable solution.

The whole process took me less time than I though it would. Knowing that each time I would like to build all versions of the game I just have to run one script it’s really satisfying and saves a lot of time. It’s worth taking the time and automate as much as you can from your daily tasks.

I know my approach is not ideal, but it is sufficient for my needs and I hope it will be usefull to you or if you know some better approach or a good way to improve write it in the comments.

Till next time!

Dodaj komentarz