Exemplo n.º 1
0
 public static async Task ClearCacheAsync(VsHive hive)
 {
     if (hive.Version.Major >= (int)VsVersion.VS2013)
     {
         await StartProcess(hive, "/clearcache").WaitForExitAsync();
     }
 }
        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());
            }
        }
Exemplo 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}\"";
        }
Exemplo n.º 4
0
 public static async Task ResetSettingsAsync(VsHive hive, string settingsName = "General.vssettings")
 => await StartProcess(hive, $"/resetsettings {settingsName} /command \"File.Exit\"").WaitForExitAsync();
Exemplo n.º 5
0
 public static async Task UpdateConfigurationAsync(VsHive hive)
 => await StartProcess(hive, "/updateconfiguration").WaitForExitAsync();
Exemplo n.º 6
0
 public static Process StartProcess(VsHive hive, string arguments = "")
 => Process.Start(hive.ApplicationPath, $"{GetRootSuffixAsArgument(hive.RootSuffix)} {arguments}");
        public static async Task <bool> IsProfileInitializedAsync(VsHive hive)
        {
            var(result, _) = await RunInstallerAsync(hive, new[] { "/IsProfileInitialized" });

            return(result == 1 ? true : false);
        }
        public static async Task <(int InstallCount, string Output)> InstallExtensionsAsync(VsHive hive, IEnumerable <string> extensions)
        {
            var(result, output) = await RunInstallerAsync(hive, new[] { "/Install" }.Concat(extensions.Select(e => QuotePath(e))));

            return(result, output);
        }