Пример #1
0
 public BuildCommand(
     IHostPlatformDetector hostPlatformDetector,
     IKnownToolProvider knownToolProvider)
 {
     _hostPlatformDetector = hostPlatformDetector;
     _knownToolProvider    = knownToolProvider;
 }
Пример #2
0
 public DefaultCommand(IActionDispatch actionDispatch, IKnownToolProvider knownToolProvider, ExecuteCommand executeCommand, IAutomatedBuildController automatedBuildController)
 {
     this.m_ActionDispatch     = actionDispatch;
     _knownToolProvider        = knownToolProvider;
     _executeCommand           = executeCommand;
     _automatedBuildController = automatedBuildController;
 }
Пример #3
0
        private void ResolveGlobalToolBinary(string workingDirectory, ICachableBinaryPackageMetadata protobuildMetadata, bool forceUpgrade)
        {
            var toolFolder = _packageGlobalTool.GetGlobalToolInstallationPath(protobuildMetadata.CanonicalURI);

            if (File.Exists(Path.Combine(toolFolder, ".pkg")))
            {
                if (!forceUpgrade)
                {
                    RedirectableConsole.WriteLine("Protobuild binary package already present at " + toolFolder);
                    return;
                }
            }

            RedirectableConsole.WriteLine("Creating and emptying " + toolFolder);
            PathUtils.AggressiveDirectoryDelete(toolFolder);
            Directory.CreateDirectory(toolFolder);

            RedirectableConsole.WriteLine("Installing " + protobuildMetadata.CanonicalURI + " at version " + protobuildMetadata.GitCommitOrRef);
            var package = GetBinaryPackage(protobuildMetadata);

            if (package == null)
            {
                RedirectableConsole.WriteLine("The specified global tool package is not available for this platform.");
                return;
            }

            ExtractTo(workingDirectory, protobuildMetadata.PackageName, protobuildMetadata.BinaryFormat, package, toolFolder, protobuildMetadata.Platform);

            var file = File.Create(Path.Combine(toolFolder, ".pkg"));

            file.Close();

            if (_knownToolProvider == null)
            {
                // We must delay load this because of a circular dependency :(
                _knownToolProvider = _lightweightKernel.Get <IKnownToolProvider>();
            }

            _packageGlobalTool.ScanPackageForToolsAndInstall(toolFolder, _knownToolProvider);

            RedirectableConsole.WriteLine("Binary resolution complete");
        }
Пример #4
0
 public DefaultCommand(IActionDispatch actionDispatch, IKnownToolProvider knownToolProvider, ExecuteCommand executeCommand)
 {
     this.m_ActionDispatch = actionDispatch;
     _knownToolProvider    = knownToolProvider;
     _executeCommand       = executeCommand;
 }
Пример #5
0
 public JSILProvider(IKnownToolProvider knownToolProvider)
 {
     _knownToolProvider = knownToolProvider;
 }
Пример #6
0
 public JSILProvider(IKnownToolProvider knownToolProvider)
 {
     _knownToolProvider = knownToolProvider;
 }
Пример #7
0
 public DefaultCommand(IActionDispatch actionDispatch, IKnownToolProvider knownToolProvider, ExecuteCommand executeCommand)
 {
     this.m_ActionDispatch = actionDispatch;
     _knownToolProvider = knownToolProvider;
     _executeCommand = executeCommand;
 }
Пример #8
0
        public void ScanPackageForToolsAndInstall(string toolFolder, IKnownToolProvider knownToolProvider)
        {
            var projectsPath = Path.Combine(toolFolder, "Build", "Projects");
            var projectsInfo = new DirectoryInfo(projectsPath);

            foreach (var file in projectsInfo.GetFiles("*.definition"))
            {
                var document = XDocument.Load(file.FullName);
                var tools    = document.XPathSelectElements("/ExternalProject/Tool");

                foreach (var tool in tools)
                {
                    var toolPath = Path.Combine(toolFolder, tool.Attribute(XName.Get("Path")).Value);
                    var toolName = tool.Attribute(XName.Get("Name")).Value;

                    if (Path.DirectorySeparatorChar == '\\')
                    {
                        toolPath = toolPath.Replace("/", "\\");
                    }
                    else if (Path.DirectorySeparatorChar == '/')
                    {
                        toolPath = toolPath.Replace("\\", "/");
                    }

                    using (var writer = new StreamWriter(Path.Combine(this.GetToolsPath(), toolName + ".tool")))
                    {
                        writer.WriteLine(toolPath);
                    }

                    RedirectableConsole.WriteLine("Global tool '" + toolName + "' now points to '" + toolPath + "'");

                    if (_hostPlatformDetector.DetectPlatform() == "Windows")
                    {
                        this.InstallToolIntoWindowsStartMenu(toolName, toolPath);
                    }
                    else if (_hostPlatformDetector.DetectPlatform() == "MacOS")
                    {
                        this.InstallToolIntoUserApplicationFolder(toolName, toolPath);
                    }
                    else if (_hostPlatformDetector.DetectPlatform() == "Linux")
                    {
                        this.InstallToolIntoLinuxApplicationMenu(toolName, toolPath);
                    }
                }

                var vsixes = document.XPathSelectElements("/ExternalProject/VSIX");

                foreach (var vsix in vsixes)
                {
                    var vsixPath = Path.Combine(toolFolder, vsix.Attribute(XName.Get("Path")).Value);

                    if (Path.DirectorySeparatorChar == '\\')
                    {
                        vsixPath = vsixPath.Replace("/", "\\");
                    }
                    else if (Path.DirectorySeparatorChar == '/')
                    {
                        vsixPath = vsixPath.Replace("\\", "/");
                    }

                    if (_hostPlatformDetector.DetectPlatform() == "Windows")
                    {
                        this.InstallVSIXIntoVisualStudio(vsixPath, knownToolProvider);
                    }
                }

                var gacs = document.XPathSelectElements("/ExternalProject/GAC");

                foreach (var gac in gacs)
                {
                    var assemblyPath = Path.Combine(toolFolder, gac.Attribute(XName.Get("Path")).Value);

                    if (Path.DirectorySeparatorChar == '\\')
                    {
                        assemblyPath = assemblyPath.Replace("/", "\\");
                    }
                    else if (Path.DirectorySeparatorChar == '/')
                    {
                        assemblyPath = assemblyPath.Replace("\\", "/");
                    }

                    if (_hostPlatformDetector.DetectPlatform() == "Windows")
                    {
                        this.InstallAssemblyIntoGAC(assemblyPath);
                    }
                }
            }
        }
Пример #9
0
        private void InstallVSIXIntoVisualStudio(string vsixPath, IKnownToolProvider knownToolProvider)
        {
            // This installation technique is for pre-2017 editions of Visual Studio.
            // We don't list 10.0 and 11.0 because they don't support all editions (you should
            // use GAC based installation for these editions instead).
            var vsVersions = new[]
            {
                "12.0",
                "14.0"
            };

            var editionRegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32)
                                     ?.OpenSubKey("SOFTWARE")
                                     ?.OpenSubKey("Microsoft")
                                     ?.OpenSubKey("VisualStudio");

            if (editionRegistryKey != null)
            {
                foreach (var version in vsVersions)
                {
                    var installPath = (string)editionRegistryKey?.OpenSubKey(version)?.GetValue("InstallDir");

                    if (installPath != null)
                    {
                        var vsixInstallerPath = Path.Combine(installPath, "VSIXInstaller.exe");

                        if (Directory.Exists(installPath))
                        {
                            if (File.Exists(vsixInstallerPath))
                            {
                                try
                                {
                                    RedirectableConsole.WriteLine("Installing VSIX into Visual Studio " + version + "...");
                                    var processStartInfo = new ProcessStartInfo();
                                    processStartInfo.FileName        = vsixInstallerPath;
                                    processStartInfo.Arguments       = "/q \"" + vsixPath + "\"";
                                    processStartInfo.UseShellExecute = false;
                                    var process = Process.Start(processStartInfo);
                                    process.WaitForExit();

                                    if (process.ExitCode != 0)
                                    {
                                        RedirectableConsole.ErrorWriteLine("VSIX installation failed for Visual Studio " + version + " (non-zero exit code)");
                                    }
                                    else
                                    {
                                        RedirectableConsole.WriteLine("VSIX installation completed successfully for Visual Studio " + version);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    RedirectableConsole.ErrorWriteLine("Failed to install VSIX for Visual Studio " + version + ": " + ex.Message);
                                }
                            }
                            else
                            {
                                RedirectableConsole.WriteLine("Visual Studio " + version + " does not provide VSIXInstaller.exe (checked for existance of " + vsixInstallerPath + ").");
                            }
                        }
                        else
                        {
                            RedirectableConsole.WriteLine("Visual Studio " + version + " is not installed (checked for existance of " + installPath + ").");
                        }
                    }
                }
            }

            // Now try and install in all editions of Visual Studio 2017 and later.  This
            // may install the vswhere global tool.
            var           vswhere       = knownToolProvider.GetToolExecutablePath("vswhere");
            List <string> installations = null;

            RedirectableConsole.WriteLine("Locating installations of Visual Studio 2017 and later...");
            try
            {
                var processStartInfo = new ProcessStartInfo();
                processStartInfo.FileName               = vswhere;
                processStartInfo.Arguments              = "-products * -property installationPath";
                processStartInfo.UseShellExecute        = false;
                processStartInfo.RedirectStandardOutput = true;
                var process             = Process.Start(processStartInfo);
                var installationsString = process.StandardOutput.ReadToEnd();
                installations = installationsString.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
                process.WaitForExit();

                if (process.ExitCode != 0)
                {
                    RedirectableConsole.ErrorWriteLine("Unable to locate Visual Studio 2017 and later installations (non-zero exit code from vswhere)");
                }
            }
            catch (Exception ex)
            {
                RedirectableConsole.ErrorWriteLine("Unable to locate Visual Studio 2017 and later installations: " + ex.Message);
            }

            if (installations != null)
            {
                foreach (var installPath in installations)
                {
                    var vsixInstallerPath = Path.Combine(installPath,
                                                         "Common7",
                                                         "IDE",
                                                         "VSIXInstaller.exe");

                    if (Directory.Exists(installPath))
                    {
                        if (File.Exists(vsixInstallerPath))
                        {
                            try
                            {
                                RedirectableConsole.WriteLine("Installing VSIX into " + installPath + "...");
                                var processStartInfo = new ProcessStartInfo();
                                processStartInfo.FileName        = vsixInstallerPath;
                                processStartInfo.Arguments       = "/q \"" + vsixPath + "\"";
                                processStartInfo.UseShellExecute = false;
                                var process = Process.Start(processStartInfo);
                                process.WaitForExit();

                                if (process.ExitCode != 0)
                                {
                                    RedirectableConsole.ErrorWriteLine("VSIX installation failed for " + installPath + " (non-zero exit code)");
                                }
                                else
                                {
                                    RedirectableConsole.WriteLine("VSIX installation completed successfully for " + installPath);
                                }
                            }
                            catch (Exception ex)
                            {
                                RedirectableConsole.ErrorWriteLine("Failed to install VSIX for " + installPath + ": " + ex.Message);
                            }
                        }
                        else
                        {
                            RedirectableConsole.WriteLine("Visual Studio at " + installPath + " does not provide VSIXInstaller.exe (checked for existance of " + vsixInstallerPath + ").");
                        }
                    }
                    else
                    {
                        RedirectableConsole.WriteLine("Visual Studio at " + installPath + " is not installed (checked for existance of " + installPath + ").");
                    }
                }
            }
        }