public static void OpenWindow()
        {
            BuildDeployWindow window = GetWindow <BuildDeployWindow>("Build Window") as BuildDeployWindow;

            if (window != null)
            {
                window.Show();
            }
        }
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            GUILayout.Space(5);
            EditorGUILayout.BeginVertical("Box");
            {
                GUILayout.Label("Update IP");

                SpectatorView.SpectatorViewManager svm = (SpectatorView.SpectatorViewManager)target;
                if (GUILayout.Button("Update Spectator View IP"))
                {
                    svm.UpdateSpectatorViewIP();
                }
            }
            EditorGUILayout.EndVertical();

            GUILayout.Space(5);
            EditorGUILayout.BeginVertical("Box");
            {
                GUILayout.Label("App Management");

                if (GUILayout.Button("Open Build Window"))
                {
                    BuildDeployWindow.OpenWindow();
                }

                GUILayout.Space(5);

                if (GUILayout.Button("Build & Deploy Apps"))
                {
                    if (!CheckCredentials())
                    {
                        Debug.LogError("Username and password must be set.");
                        BuildDeployWindow.OpenWindow();
                        return;
                    }

                    BuildDeployPrefs.TargetIPs = BuildIPsList();

                    BuildDeployWindow buildWindow = BuildDeployWindow.GetBuildWindow();
                    buildWindow.BuildAndRun(PlayerSettings.productName);
                }

                if (GUILayout.Button("Deploy Apps"))
                {
                    if (!CheckCredentials())
                    {
                        Debug.LogError("Username and password must be set.");
                        BuildDeployWindow.OpenWindow();
                        return;
                    }

                    BuildDeployPrefs.TargetIPs = BuildIPsList();

                    BuildDeployWindow buildWindow = BuildDeployWindow.GetBuildWindow();
                    buildWindow.Install();
                }

                if (GUILayout.Button("Start Apps"))
                {
                    if (!CheckCredentials())
                    {
                        Debug.LogError("Username and password must be set.");
                        BuildDeployWindow.OpenWindow();
                        return;
                    }

                    BuildDeployWindow buildWindow = BuildDeployWindow.GetBuildWindow();
                    string            ips         = BuildIPsList();

                    // Always kill first so that we have a clean state
                    buildWindow.KillAppOnIPs(ips);
                    buildWindow.LaunchAppOnIPs(ips);
                }

                if (GUILayout.Button("Terminate Apps"))
                {
                    if (!CheckCredentials())
                    {
                        Debug.LogError("Username and password must be set.");
                        BuildDeployWindow.OpenWindow();
                        return;
                    }

                    BuildDeployWindow buildWindow = BuildDeployWindow.GetBuildWindow();
                    buildWindow.KillAppOnIPs(BuildIPsList());
                }
            }
            EditorGUILayout.EndVertical();
        }
        public static bool BuildAppxFromSolution(string productName, string msBuildVersion, bool forceRebuildAppx, string buildConfig, string buildDirectory, bool incrementVersion)
        {
            // Get and validate the msBuild path...
            string vs = CalcMSBuildPath(msBuildVersion);

            if (!File.Exists(vs))
            {
                Debug.LogError("MSBuild.exe is missing or invalid (path=" + vs + "). Note that the default version is " + DefaultMSBuildVersion);
                return(false);
            }

            // Get the path to the NuGet tool
            string unity               = Path.GetDirectoryName(EditorApplication.applicationPath);
            string nugetPath           = Path.Combine(unity, @"Data\PlaybackEngines\MetroSupport\Tools\NuGet.exe");
            string storePath           = Path.GetFullPath(Path.Combine(Path.Combine(Application.dataPath, ".."), buildDirectory));
            string solutionProjectPath = Path.GetFullPath(Path.Combine(storePath, productName + @".sln"));

            // Before building, need to run a nuget restore to generate a json.lock file. Failing to do
            // this breaks the build in VS RTM
            var nugetPInfo = new System.Diagnostics.ProcessStartInfo();

            nugetPInfo.FileName         = nugetPath;
            nugetPInfo.WorkingDirectory = buildDirectory;
            nugetPInfo.UseShellExecute  = false;
            nugetPInfo.Arguments        = @"restore " + PlayerSettings.productName + "/project.json";
            using (var nugetP = new System.Diagnostics.Process())
            {
                Debug.Log(nugetPath + " " + nugetPInfo.Arguments);
                nugetP.StartInfo = nugetPInfo;
                nugetP.Start();
                nugetP.WaitForExit();
            }

            // Ensure that the generated .appx version increments by modifying
            // Package.appxmanifest
            if (incrementVersion)
            {
                IncrementPackageVersion();
            }

            // Now do the actual build
            var pinfo = new System.Diagnostics.ProcessStartInfo();

            pinfo.FileName        = vs;
            pinfo.UseShellExecute = false;
            string buildType = forceRebuildAppx ? "Rebuild" : "Build";

            pinfo.Arguments = string.Format("\"{0}\" /t:{2} /p:Configuration={1} /p:Platform=x86", solutionProjectPath, buildConfig, buildType);
            var p = new System.Diagnostics.Process();

            Debug.Log(vs + " " + pinfo.Arguments);
            p.StartInfo = pinfo;
            p.Start();

            p.WaitForExit();
            if (p.ExitCode == 0)
            {
                Debug.Log("APPX build succeeded!");
            }
            else
            {
                Debug.LogError("MSBuild error (code = " + p.ExitCode + ")");
            }

            if (p.ExitCode != 0)
            {
                EditorUtility.DisplayDialog(PlayerSettings.productName + " build Failed!", "Failed to build appx from solution. Error code: " + p.ExitCode, "OK");
                return(false);
            }
            else
            {
                // Build succeeded. Allow user to install build on remote PC
                BuildDeployWindow.OpenWindow();
                return(true);
            }
        }