public static async Task <(int Result, string Output)> RunInstallerAsync(VsHive hive, IEnumerable <string> args)
        {
            var suffix = hive.Version >= VersionUtil.FromVsVersion(VsVersion.VS2022) ? ".x64" : string.Empty;

            using (var visualStudioInstaller = new TempFile(EmbeddedResourceUtil.ExtractResource(Assembly.GetExecutingAssembly(), $"VsixTesting.Installer{suffix}.exe")))
            {
                var process = Process.Start(new ProcessStartInfo
                {
                    FileName  = visualStudioInstaller.Path,
                    Arguments = string.Join(" ", new string[]
                    {
                        "/ApplicationPath", QuotePath(hive.ApplicationPath),
                        "/RootSuffix", hive.RootSuffix,
                    }.Concat(args)),
                    CreateNoWindow         = true,
                    UseShellExecute        = false,
                    RedirectStandardError  = true,
                    RedirectStandardOutput = true,
                });

                await process.WaitForExitAsync();

                if (process.ExitCode < 0)
                {
                    throw new Exception(process.StandardError.ReadToEnd());
                }

                return(process.ExitCode, process.StandardOutput.ReadToEnd());
            }
        }
Esempio n. 2
0
        public static async Task Prepare(VsHive hive, IEnumerable <string> extensionsToInstall, bool resetSettings, IDiagnostics diagnostics)
        {
            await diagnostics.RunAsync("Preparing Instance", async output =>
            {
                var installResult   = default((int InstallCount, bool HasSettingsFile, string Output));
                var invokerAssembly = Assembly.GetExecutingAssembly();

                using (var invoker = new TempFile(EmbeddedResourceUtil.ExtractResource(invokerAssembly, "VsixTesting.Invoker.vsix")))
                {
                    EmbeddedResourceUtil.ApplyDateTime(invoker.Path, invokerAssembly, "VsixTesting.Invoker.vsix");

                    installResult = await VisualStudioUtil.InstallExtensionsAsync(
                        hive,
                        extensionsToInstall.Concat(new[] { invoker.Path }));

                    output.WriteLine(installResult.Output);

                    if (installResult.InstallCount > 0)
                    {
                        output.WriteLine("Clearing cache");
                        await VisualStudioUtil.ClearCacheAsync(hive);
                        output.WriteLine("Updating configuration");
                        await VisualStudioUtil.UpdateConfigurationAsync(hive);
                    }
                }

                if (!installResult.HasSettingsFile || resetSettings)
                {
                    output.WriteLine("Resetting settings");
                    await VisualStudioUtil.ResetSettingsAsync(hive);
                }
            });
        }
Esempio n. 3
0
        public static async Task <(int InstallCount, bool HasSettingsFile, string Output)> InstallExtensionsAsync(VsHive hive, IEnumerable <string> extensions)
        {
            using (var visualStudioInstaller = new TempFile(EmbeddedResourceUtil.ExtractResource(Assembly.GetExecutingAssembly(), "VsixTesting.ExtensionInstaller.exe")))
            {
                var process = Process.Start(new ProcessStartInfo
                {
                    FileName  = visualStudioInstaller.Path,
                    Arguments = string.Join(" ", new string[]
                    {
                        "--ApplicationPath", Quote(hive.ApplicationPath),
                        "--RootSuffix", hive.RootSuffix,
                        "--MajorVersion", hive.Version.Major.ToString(),
                        "--ExtensionPaths",
                    }.Concat(extensions.Select(e => Quote(e)))),
                    CreateNoWindow         = true,
                    UseShellExecute        = false,
                    RedirectStandardError  = true,
                    RedirectStandardOutput = true,
                });

                await process.WaitForExitAsync();

                var result          = process.ExitCode;
                var hasSettingsFile = true;

                if (result < 0)
                {
                    throw new Exception(process.StandardError.ReadToEnd());
                }
                else if (result >= 9999)
                {
                    result         -= 9999;
                    hasSettingsFile = false;
                }

                return(result, hasSettingsFile, process.StandardOutput.ReadToEnd());
            }

            string Quote(string str) => $"\"{str}\"";
        }
Esempio n. 4
0
        public static async Task Prepare(VsHive hive, IEnumerable <string> extensionsToInstall, bool resetSettings, IDiagnostics diagnostics, bool installInvoker = true)
        {
            await diagnostics.RunAsync("Preparing Instance", async output =>
            {
                var invokerAssembly = Assembly.GetExecutingAssembly();
                var resourceName    = $"VsixTesting.Invoker{(hive.Version.Major >= 17 ? ".17" : string.Empty)}.vsix";

                using (var invoker = new TempFile(EmbeddedResourceUtil.ExtractResource(invokerAssembly, resourceName)))
                {
                    EmbeddedResourceUtil.ApplyDateTime(invoker.Path, invokerAssembly, resourceName);

                    if (installInvoker)
                    {
                        extensionsToInstall = extensionsToInstall.Concat(new[] { invoker.Path });
                    }

                    var installResult = await VisualStudioUtil.InstallExtensionsAsync(hive, extensionsToInstall);

                    output.WriteLine(installResult.Output);

                    if (installResult.InstallCount > 0)
                    {
                        output.WriteLine("Clearing cache");
                        await VisualStudioUtil.ClearCacheAsync(hive);
                        output.WriteLine("Updating configuration");
                        await VisualStudioUtil.UpdateConfigurationAsync(hive);
                    }
                }

                if (resetSettings)
                {
                    output.WriteLine("Resetting settings");
                    await VisualStudioUtil.ResetSettingsAsync(hive);
                }
            });
        }