Documentation

Support

Automate local deployment

Automate the deployment of your Cloud Code module with the Unity Gaming Services CLI or project file.
Read time 2 minutesLast updated 18 hours ago

This guide shows you how to automate the deployment of your Cloud Code module with the Unity Gaming Services (UGS) CLI or the project file. If you want to integrate the deployment into your CI/CD pipeline, refer to Integrating with CI/CD.

Prerequisites

You need a Cloud Code module and the UGS CLI to automate local deployment:
  1. Create a Cloud Code module.
  2. Follow the steps in Install the CLI (Unity Gaming Services CLI) to install, configure and authenticate the UGS CLI.

Automate with the UGS CLI

The UGS CLI provides a
deploy
command that you can use to deploy a solution. The
deploy
command zips the module and deploys it to the Cloud Code service.
To deploy, run the following command from your terminal in your project directory:
ugs deploy <path_to_solution>

Automate using the project file

You can use the project file to automate the deployment of your Cloud Code module if you configure the project file to publish, zip and deploy your project on build. For more information, refer to Microsoft guide on Understanding the project file. The script uses the UGS CLI Deploy command.

Project file configuration

You can use the following project file configuration to automate the deployment of your Cloud Code module:
<Target Name="RemoveDirectory"> <RemoveDir Directories="$(OutDir)Module/" /> </Target><Target Name="PublishModule" DependsOnTargets="RemoveDirectory"> <Exec Command="dotnet publish -r linux-x64 --no-self-contained -o $(OutDir)Module/$(AssemblyName)" /></Target><Target Name="ZipModule" DependsOnTargets="PublishModule"> <ZipDirectory SourceDirectory="$(OutDir)Module/$(AssemblyName)" DestinationFile="$(OutDir)Module/$(AssemblyName).ccm" /></Target><Target Name="DeployModule" DependsOnTargets="ZipModule"> <Exec Command="ugs deploy $(OutDir)/Module/$(AssemblyName).ccm" /></Target>
Copy and paste the above configuration into your project file.
  • The
    RemoveDirectory
    target removes the
    Module
    directory from the
    OutDir
    directory.
  • The
    PublishModule
    target publishes the module to the
    Module
    directory and produces the required assemblies.
  • The
    ZipModule
    target zips the
    Module
    directory.
  • The
    DeployModule
    target deploys the module to the Cloud Code service.

Ready to Run compilation (optional)

Ready to Run compilation is an optional feature that improves the cold start time of your Cloud Code module. To check how this option affects your module, refer to Ready to Run. To enable Ready to Run compilation, modify the
PublishModule
target to include the
PublishReadyToRun
property:
<Target Name="PublishModule" DependsOnTargets="RemoveDirectory"> <Exec Command="dotnet publish -r linux-x64 -p:PublishReadyToRun=true --no-self-contained -o $(OutDir)Module/$(AssemblyName)" /></Target>

Running targets

To run the targets, run the following command from your terminal in your project directory:
msbuild /t:DeployModule
If the
msbuild 
command is not found, you may need to add the
msbuild
path to your
PATH
environment variable.

Expected output

If the deployment is successful, the following output is displayed:
Deployed:ExampleModule.ccm