Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

BuildManifestObject interface

Discussion in 'Unity Build Automation' started by ortin, Mar 18, 2016.

  1. ortin

    ortin

    Joined:
    Jan 13, 2013
    Posts:
    221
    In docs here https://build.cloud.unity3d.com/support/guides/manifest/ (BuildManifestObject tab) there is an example of using the manifest object
    Code (CSharp):
    1. manifest.GetValue("buildNumber", "unknown")
    but in the public interface of it posted below on the same page there is no method with such signature.
    Code (CSharp):
    1. namespace UnityEngine.CloudBuild
    2. {
    3.     public class BuildManifestObject : ScriptableObject
    4.     {
    5.         // Tries to get a manifest value - returns true if key was found and could be cast to type T, false otherwise.
    6.         public bool TryGetValue<T>(string key, out T result);
    7.  
    8.         // Retrieve a manifest value or throw an exception if the given key isn't found.
    9.         public T GetValue<T>(string key);
    10.  
    11.         // Sets the value for a given key.
    12.         public void SetValue(string key, object value);
    13.  
    14.         // Copy values from a dictionary. ToString() will be called on dictionary values before being stored.
    15.         public void SetValues(Dictionary<string, object> sourceDict);
    16.  
    17.         // Remove all key/value pairs
    18.         public void ClearValues();
    19.  
    20.         // Returns a Dictionary that represents the current BuildManifestObject
    21.         public Dictionary<string, object> ToDictionary();
    22.  
    23.         // Returns a JSON formatted string that represents the current BuildManifestObject
    24.         public string ToJson();
    25.  
    26.         // Returns an INI formatted string that represents the current BuildManifestObject
    27.         public override string ToString();
    28.     }
    29. }
    So is it an error in the example or in the interface?
     
  2. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    332
    Just double checked, the error is in the example. The interface is what you want to use.
     
    GarthSmith and ortin like this.
  3. Calvin2274

    Calvin2274

    Joined:
    Sep 11, 2014
    Posts:
    17
    error CS0234: The type or namespace name `CloudBuild' does not exist in the namespace `UnityEngine'. Are you missing an assembly reference?

    Am i have to create the BuildManifestObject class by myself ?
     
  4. Ash-Blue

    Ash-Blue

    Joined:
    Aug 18, 2013
    Posts:
    102
    The documentation is rather confusing. Does this file need to be created or is there a missing interface class that we should be using. Also `BuildManifestObject` doesn't exist in Unity as far as I can tell.
     
  5. jknight-nc

    jknight-nc

    Joined:
    Jun 10, 2014
    Posts:
    52
    The documentation and the lack of including a stub for testing this makes developing for this interface extremely error prone.

    You have to wrap your pre export in #IF UNITY_CLOUD_BUILD so you can't even check it for errors before submitting it to cloud build. Then it fails on the server because the documentation and examples are wrong.

    For example, how are we supposed to know what type to supply to manifest.GetValue<T>("buildNumber", "unknown") ??
     
    Last edited: May 19, 2017
  6. Dazo1985

    Dazo1985

    Joined:
    Mar 13, 2019
    Posts:
    26
    Qhuhuit likes this.
  7. Immu

    Immu

    Joined:
    Jun 18, 2013
    Posts:
    239
    It is 2021 and it is still confusing.
    Please do something
    @Ryanc_unity
     
    sreimonenq likes this.
  8. AdamBebko

    AdamBebko

    Joined:
    Apr 8, 2016
    Posts:
    161
    still in dec 2021.
     
  9. rajivrao

    rajivrao

    Unity Technologies

    Joined:
    Feb 19, 2019
    Posts:
    111
    Thanks for re-flagging @AdamBebko. Bringing this up with our docs team to see how we can use the feedback in this thread to improve.
     
  10. AdamBebko

    AdamBebko

    Joined:
    Apr 8, 2016
    Posts:
    161
    Great to hear. Just to add, the example's GetValue method is deprecated now.

    Here's the script I use. It improves on the example in several ways.
    • minimizes code inside the #if so you can catch more compiler errors
    • swaps deprecated method for new one
    • Allows you to set major and minor release in project settings, without overwriting them.
    Code (CSharp):
    1. using System;
    2. using JetBrains.Annotations;
    3. using UnityEditor;
    4. using UnityEngine;
    5.  
    6. namespace BuildScripts
    7. {
    8.  
    9.     public class PreExportScript : MonoBehaviour
    10.     {
    11. #if UNITY_CLOUD_BUILD
    12.         public static void PreExport(UnityEngine.CloudBuild.BuildManifestObject manifest)
    13.         {
    14.             int buildNumber = manifest.GetValue<int>("buildNumber");
    15.             UpdateVersionBuildNumber(buildNumber);
    16.         }
    17. #endif
    18.         [PublicAPI]
    19.         static void UpdateVersionBuildNumber(int buildNumber)
    20.         {
    21.             Debug.Log("Pre Export Script: Updating version build number.");
    22.             Version oldVersion = Version.Parse(PlayerSettings.bundleVersion);
    23.             Version newVersion = new Version(oldVersion.Major, oldVersion.Minor, buildNumber);
    24.             Debug.Log($"Pre Export Script: Version changed from {oldVersion} to {newVersion}.");
    25.             PlayerSettings.bundleVersion = newVersion.ToString();
    26.         }
    27.     }
    28. }
    edit: I added in a jet brains annotation feature [PublicAPI] this can be omitted if desired.