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:- Create a Cloud Code module.
- 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 adeploydeployugs 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:Copy and paste the above configuration into your project file.<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>
- The target removes the
RemoveDirectorydirectory from theModuledirectory.OutDir - The target publishes the module to the
PublishModuledirectory and produces the required assemblies.Module - The target zips the
ZipModuledirectory.Module - The target deploys the module to the Cloud Code service.
DeployModule
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 thePublishModulePublishReadyToRun<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:If themsbuild /t:DeployModule
msbuild msbuildPATHExpected output
If the deployment is successful, the following output is displayed:Deployed:ExampleModule.ccm