Maxime FRAPPAT

Hum …no thanks ! – Lordinaire

Category: C# (Page 1 of 14)

Build and deploy your Unity game with Visual Studio Online and App Center – Part 2

When you develop a game with Unity3D and you want to take advantage of the Microsoft ecosystem like Visual Studio Online, it can be hard to configure your CI/CD environment. This blog post will explain how to set up that from pushing code to deploy the game on device automatically.

  • Part 1 : Build with Unity CLI
  • Part 2 : Continuous Integration with Visual Studio Online
  • Part 3 : Continuous Delivery with Visual Studio Online
  • Part 4 : Deploy with App Center

Continuous Integration with Visual Studio Online

Well, you are a big fan of Visual Studio Online to manage all your projects (me too!) so let’s create a new one, mine is using Git. Once the difficult task of finding the right project name done, click on the setting wheel and select Agent Queues.

You need to set up a machine that will build the project, it can be a virtual machine (like on Azure) or your actual machine (not ideal but works well for a demonstration). We will use the second option to simplify.

Click on  and follow all the steps. Once the agent created, select it and add a new capability :

The capability will be use later to filter the list of agent in order to select the one that can work with Unity project. It is not mandatory if you have a queue with the same type of agent but a good practice if you work with many different agents.

It’s time to create the build definition, select the Build menu and click on the New button :

Select the pool agent where you have install your agent (mine is Default) :

Add a Batch Script task :

Add a Publish Build Artifacts task :

Don’t forget to enable continuous integration :

… and to select an agent that can handle Unity project :

That’s all. You can save your build definition and queue a new build or push code in your repository. In the next post, we will see how to send the generated apk file to App Center with a release definition.

 

Build and deploy your Unity game with Visual Studio Online and App Center – Part 1

When you develop a game with Unity3D and you want to take advantage of the Microsoft ecosystem like Visual Studio Online, it can be hard to configure your CI/CD environment. This blog post will explain how to set up that from pushing code to deploy the game on device automatically.

I can’t cover all platforms so I will only focus on Android. It’s pretty much the same stuff  for other platforms. The name of the game will be : “Adam Must Live” (yes, it’s an in progress game ;))

Unity CLI

So, you have a game that you want to build for the Android platform. Great! What’s next ? Command line arguments.

The first thing to do is to create a script that can be used to build the game without any user interaction and the Unity CLI is the perfect target for doing that. Create a folder named Editor in your Assets folder and add a new script named MyEditorScript.cs :

using System.IO;
using System.Linq;
using UnityEditor;

public class MyEditorScript
{
    public static void PerformBuild()
    {
        // Get all actives scenes
        var scenes = EditorBuildSettings.scenes.Where(s => s.enabled).Select(s => s.path).ToArray();

        var outputFile = "./Builds/Android/AdamMustLive.apk";
        if (File.Exists(outputFile))
        {
            File.Delete(outputFile);
        }

        var buildPlayerOptions =
            new BuildPlayerOptions
            {
                scenes = scenes,
                locationPathName = outputFile,
                target = BuildTarget.Android,
                options = BuildOptions.None
            };
        BuildPipeline.BuildPlayer(buildPlayerOptions);
    }
}

This static method can now be called be the CLI to build the game and generate the .apk file. We just need to run the command :

C:\Program Files\Unity\Hub\Editor\2018.1.1f1\Editor\Unity.exe -quit -batchmode -projectPath UNITY_PROJECT_PATH -executeMethod MyEditorScript.PerformBuild

We use the -batchmode to run Unity editor in a non-interactive mode (no user interaction will be required). The -quit option forces Unity to close himself when the task ends.

If you planned to install Unity on a machine hat don’t have a graphic card, you may need to add the parameter -nographics but some restrictions will be applied.

In the next post, we will see how to create a build definition with Visual Studio Online.

 

Page 1 of 14

Powered by WordPress & Theme by Anders Norén

%d bloggers like this: