コード例 #1
0
        private BuildStepResults StartAppX(string fullPackageName, string args, out uint pid)
        {
            Console.WriteLine("Starting AppX ...");

            BuildStepResults res = new BuildStepResults();

            pid = 0;


            // Need "App user model id". Clean ways of doing this...
            // * Read AppX Manifest to find out the user model id (is there an easier way that is also not based on hacking?)
            // * Could at least extract the family name instead of guessing
            // * ??
            // -> In any (known) case we would need something like Windows.Management.Deployment.PackageManager.FindPackage which brings WinRT dependencies into this project.
            //
            // The following method seems to work just fine for ezEngine projects if not for all AppX in general.
            //
            // From experience (documentation link?) we know that the user model id is the AppX family name + "!" + entry point.
            // We also know, that the family name is like the fullPackageName without version and platform numbers.
            // The AppX name (first part) and the suffix can't contain underscores, so it can safely be split with '_'
            var    packageNameParts = fullPackageName.Split('_');
            string appFamilyName    = packageNameParts[0] + "_" + packageNameParts[packageNameParts.Length - 1];
            string appUserModelId   = appFamilyName + "!App"; // Apply our knowledge of ezEngine's appx manifests.

            try
            {
                IntPtr errorCode = appActiveManager.ActivateApplication(appUserModelId, args, ActivateOptions.None, out pid);
                if (errorCode.ToInt64() != 0)
                {
                    res.Error("Activating appx '{0}' failed with error code {1}.", fullPackageName, errorCode.ToInt64());
                    return(res);
                }
            }
            catch (Exception e)
            {
                res.Error("Failed to activate appx: {0}", e);
                return(res);
            }

            res.Success = true;
            return(res);
        }
コード例 #2
0
        private BuildStepResults DeployAppX(ezCMake.TestTarget target, BuildMachineSettings settings, out string fullPackageName)
        {
            Console.WriteLine("Deploying AppX ...");

            BuildStepResults result = new BuildStepResults();

            fullPackageName = "";

            string absSlnPath = Path.Combine(settings.AbsCMakeWorkspace, "ezEngine.sln");

            if (!File.Exists(absSlnPath))
            {
                result.Error("Visual Studio solution '{0}' does not exist.", absSlnPath);
                return(result);
            }


            // VSLauncher vs using devenv.exe directly.
            //
            // Pro VSLauncher:
            // - It picks always the appropriate VS version
            // - We know more certainly where it is
            //
            // Con VSLauncher:
            // - Spawns devenv.exe and closes again (we don't know when devenv.exe finishes or if it came up in the first place)
            // - No console output

            //string VSLauncherAbsPath = Environment.ExpandEnvironmentVariables(VSLauncherLocation);
            //if (!File.Exists(VSLauncherAbsPath))
            //{
            //  result.Error("Did not find Visual Studio launcher at '{0}'.", VSLauncherAbsPath);
            //  return result;
            //}

            // Using this registry key we should always get the newest devenv version.
            // Since newer versions can use old compilers & SDKs this should be perfectly fine.
            // https://social.msdn.microsoft.com/Forums/vstudio/en-US/568e32af-d724-4ac6-8e8f-72181c4320b3/set-default-version-of-visual-studio?forum=vssetup
            string devEnvPath;

            try
            {
                using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\App Paths\devenv.exe"))
                {
                    if (key != null)
                    {
                        devEnvPath = key.GetValue("") as string;
                        if (devEnvPath == null)
                        {
                            result.Error("Failed to read Visual Studio location from registry key: No string value in key found.");
                            return(result);
                        }
                    }
                    else
                    {
                        result.Error("Failed to read Visual Studio location from registry key: Registry key not found.");
                        return(result);
                    }
                }
            }
            catch (Exception e)
            {
                result.Error("Failed to read Visual Studio location from registry key: {0}", e);
                return(result);
            }

            // Use ".com" version which writes into stdout
            devEnvPath = devEnvPath.Replace("devenv.exe", "devenv.com");

            if (!File.Exists(devEnvPath))
            {
                result.Error("Did not find Visual Studio installation at '{0}'.", devEnvPath);
                return(result);
            }

            // "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\devenv.com" "F:\Development\current_development\ezEngine\build_uwp64\ezEngine.sln" /Deploy "RelWithDebInfo|x64" /project CoreTest

            string platform             = settings.Configuration.EndsWith("64") ? "x64" : "Win32"; // No ARM support yet.
            var    deployProcessResults = ezProcessHelper.RunExternalExe(devEnvPath,
                                                                         string.Format("\"{0}\" /Deploy \"{1}|{2}\" /project {3}", absSlnPath, settings.BuildType, platform, target.Name), null, result);

            result.Duration = deployProcessResults.Duration;
            if (deployProcessResults.ExitCode != 0)
            {
                result.Error("Deployment failed:\n{0}", deployProcessResults.StdOut);
                result.Success = false;
            }
            else
            {
                // Get full package name from deploy output.
                // From the build configuration we only know the package name, not the full identifier. This little parse saves us from searching the package registry.
                string fullPackageNameStartString = "Full package name: \"";
                int    begin = deployProcessResults.StdOut.LastIndexOf(fullPackageNameStartString) + fullPackageNameStartString.Length;
                int    end   = deployProcessResults.StdOut.IndexOf("\"", begin);
                if (begin < 0 || end < 0)
                {
                    result.Error("Failed to parse full package name from Visual Studio output. Output was:\n'{0}'.", deployProcessResults.StdOut);
                    return(result);
                }
                fullPackageName = deployProcessResults.StdOut.Substring(begin, end - begin);

                result.Success = true;
            }

            return(result);
        }