Search Unity

How to retrieve file extension for BuildTarget in Pipeline?

Discussion in 'Testing & Automation' started by Xarbrough, Aug 1, 2019.

  1. Xarbrough

    Xarbrough

    Joined:
    Dec 11, 2014
    Posts:
    1,188
    Is there a way of using Unity's API to build an output path for a BuildPlayer call that includes the correct file extension depending on the output target? Currently, we have to implement this logic ourselves, e.g. when building for Standalone Windows, append ".exe" to the path, when building for Android, append ".apk" and so on. It's totally doable, but feels like redundant code, since Unity is already handling all of this internally. Am I simply missing the API call to get this extension or default output path where I can extract the extension or something like this?
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    The output of a standalone build is a folder, so it doesn't have an extension.

    Also, Android builds may now contain more than 1 file (e.g split APKs).

    You can use the PostProcessBuild attribute to get a callback with the built path. For Standalone you know that the file extension is exe (or .app on OSX), I don't know of any other way to obtain this.

    A newer alternative is to use the IPostprocessBuildWithReport which includes a BuildReport object that has more details, maybe that can help you out :)
     
  3. Johannski

    Johannski

    Joined:
    Jan 25, 2014
    Posts:
    826
    I ran into the same question. @liortal not sure if you got the issue correctly. It is about providing a path for the build, not checking afterwards what has been built. If I provide a folder as the build path I get the following error:

    Code (CSharp):
    1. ArgumentException: For the 'StandaloneWindows64' target the 'locationPathName' parameter for BuildPipeline.BuildPlayer should not end with a directory separator.
    2. Provided path: 'Builds/StandaloneWindows64/2022.3.7f1/GameJam/', expected a path with the extension '.exe'.
    3. UnityEditor.BuildPipeline.BuildPlayer (System.String[] scenes, System.String locationPathName, System.String assetBundleManifestPath, UnityEditor.BuildTargetGroup buildTargetGroup, UnityEditor.BuildTarget target, System.Int32 subtarget, UnityEditor.BuildOptions options, System.String[] extraScriptingDefines) (at <97436df440ca462884c5332c1d8ebbe7>:0)
    4. UnityEditor.BuildPipeline.BuildPlayer (UnityEditor.BuildPlayerOptions buildPlayerOptions) (at <97436df440ca462884c5332c1d8ebbe7>:0)
    5. UnityBuilderAction.BuildScript.Build (UnityEditor.BuildTarget buildTarget, System.String filePath) (at Assets/_Project/02_Core/02_Scripts/Pipeline/Editor/BuildScript.cs:221)
    6. UnityBuilderAction.BuildScript.Build (System.String[] args) (at Assets/_Project/02_Core/02_Scripts/Pipeline/Editor/BuildScript.cs:111)
    7. UnityBuilderAction.BuildScriptMenu.BuildWithParameters (System.Collections.Generic.List`1[T] parameters) (at Assets/_Project/02_Core/02_Scripts/Pipeline/Editor/BuildScriptMenu.cs:62)
    8. UnityBuilderAction.BuildScriptMenu.BuildReleaseVersion () (at Assets/_Project/02_Core/02_Scripts/Pipeline/Editor/BuildScriptMenu.cs:42)
    9.