public static void PerformBuild(BuildInfo buildInfo) { BuildTargetGroup buildTargetGroup = GetGroup(buildInfo.BuildTarget); string oldBuildSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(buildTargetGroup); if (!string.IsNullOrEmpty(oldBuildSymbols)) { if (buildInfo.HasConfigurationSymbol()) { buildInfo.AppendSymbols(BuildInfo.RemoveConfigurationSymbols(oldBuildSymbols)); } else { buildInfo.AppendSymbols(oldBuildSymbols.Split(';')); } } if ((buildInfo.BuildOptions & BuildOptions.Development) == BuildOptions.Development) { if (!buildInfo.HasConfigurationSymbol()) { buildInfo.AppendSymbols(BuildSLNUtilities.BuildSymbolDebug); } } if (buildInfo.HasAnySymbols(BuildSLNUtilities.BuildSymbolDebug)) { buildInfo.BuildOptions |= BuildOptions.Development | BuildOptions.AllowDebugging; } if (buildInfo.HasAnySymbols(BuildSLNUtilities.BuildSymbolRelease)) { //Unity automatically adds the DEBUG symbol if the BuildOptions.Development flag is //specified. In order to have debug symbols and the RELEASE symbole we have to //inject the symbol Unity relies on to enable the /debug+ flag of csc.exe which is "DEVELOPMENT_BUILD" buildInfo.AppendSymbols("DEVELOPMENT_BUILD"); } var oldBuildTarget = EditorUserBuildSettings.activeBuildTarget; EditorUserBuildSettings.SwitchActiveBuildTarget(buildInfo.BuildTarget); var oldWSASDK = EditorUserBuildSettings.wsaSDK; if (buildInfo.WSASdk.HasValue) { EditorUserBuildSettings.wsaSDK = buildInfo.WSASdk.Value; } WSAUWPBuildType?oldWSAUWPBuildType = null; if (EditorUserBuildSettings.wsaSDK == WSASDK.UWP) { oldWSAUWPBuildType = EditorUserBuildSettings.wsaUWPBuildType; if (buildInfo.WSAUWPBuildType.HasValue) { EditorUserBuildSettings.wsaUWPBuildType = buildInfo.WSAUWPBuildType.Value; } } var oldWSAGenerateReferenceProjects = EditorUserBuildSettings.wsaGenerateReferenceProjects; if (buildInfo.WSAGenerateReferenceProjects.HasValue) { EditorUserBuildSettings.wsaGenerateReferenceProjects = buildInfo.WSAGenerateReferenceProjects.Value; } var oldColorSpace = PlayerSettings.colorSpace; if (buildInfo.ColorSpace.HasValue) { PlayerSettings.colorSpace = buildInfo.ColorSpace.Value; } if (buildInfo.BuildSymbols != null) { PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, buildInfo.BuildSymbols); } string buildError = "Error"; try { // For the WSA player, Unity builds into a target directory. // For other players, the OutputPath parameter indicates the // path to the target executable to build. if (buildInfo.BuildTarget == BuildTarget.WSAPlayer) { Directory.CreateDirectory(buildInfo.OutputDirectory); } OnPreProcessBuild(buildInfo); buildError = BuildPipeline.BuildPlayer( buildInfo.Scenes.ToArray(), buildInfo.OutputDirectory, buildInfo.BuildTarget, buildInfo.BuildOptions); if (buildError.StartsWith("Error")) { throw new Exception(buildError); } } finally { OnPostProcessBuild(buildInfo, buildError); PlayerSettings.colorSpace = oldColorSpace; PlayerSettings.SetScriptingDefineSymbolsForGroup(buildTargetGroup, oldBuildSymbols); EditorUserBuildSettings.wsaSDK = oldWSASDK; if (oldWSAUWPBuildType.HasValue) { EditorUserBuildSettings.wsaUWPBuildType = oldWSAUWPBuildType.Value; } EditorUserBuildSettings.wsaGenerateReferenceProjects = oldWSAGenerateReferenceProjects; EditorUserBuildSettings.SwitchActiveBuildTarget(oldBuildTarget); } }