public static IEnumerable <VcVarsBatFile> GetCandidateVcVarsFiles(IBuildActions actions)
        {
            var programFilesx86 = actions.GetEnvironmentVariable("ProgramFiles(x86)");

            if (programFilesx86 is null)
            {
                yield break;
            }

            // Attempt to use vswhere to find installations of Visual Studio
            var vswhere = actions.PathCombine(programFilesx86, "Microsoft Visual Studio", "Installer", "vswhere.exe");

            if (actions.FileExists(vswhere))
            {
                var exitCode1 = actions.RunProcess(vswhere, "-prerelease -legacy -property installationPath", null, null, out var installationList);
                var exitCode2 = actions.RunProcess(vswhere, "-prerelease -legacy -property installationVersion", null, null, out var versionList);

                if (exitCode1 == 0 && exitCode2 == 0 && versionList.Count == installationList.Count)
                {
                    // vswhere ran successfully and produced the expected output
                    foreach (var vsInstallation in versionList.Zip(installationList, (v, i) => (Version: v, InstallationPath: i)))
                    {
                        var dot = vsInstallation.Version.IndexOf('.');
                        var majorVersionString = dot == -1 ? vsInstallation.Version : vsInstallation.Version.Substring(0, dot);
                        if (int.TryParse(majorVersionString, out var majorVersion))
                        {
                            if (majorVersion < 15)
                            {
                                // Visual Studio 2015 and below
                                yield return(new VcVarsBatFile(actions.PathCombine(vsInstallation.InstallationPath, @"VC\vcvarsall.bat"), majorVersion));
                            }
                            else
                            {
                                // Visual Studio 2017 and above
                                yield return(new VcVarsBatFile(actions.PathCombine(vsInstallation.InstallationPath, @"VC\Auxiliary\Build\vcvars32.bat"), majorVersion));

                                yield return(new VcVarsBatFile(actions.PathCombine(vsInstallation.InstallationPath, @"VC\Auxiliary\Build\vcvars64.bat"), majorVersion));

                                yield return(new VcVarsBatFile(actions.PathCombine(vsInstallation.InstallationPath, @"Common7\Tools\VsDevCmd.bat"), majorVersion));
                            }
                        }
                        // else: Skip installation without a version
                    }
                    yield break;
                }
            }

            // vswhere not installed or didn't run correctly - return legacy Visual Studio versions
            yield return(new VcVarsBatFile(actions.PathCombine(programFilesx86, @"Microsoft Visual Studio 14.0\VC\vcvarsall.bat"), 14));

            yield return(new VcVarsBatFile(actions.PathCombine(programFilesx86, @"Microsoft Visual Studio 12.0\VC\vcvarsall.bat"), 12));

            yield return(new VcVarsBatFile(actions.PathCombine(programFilesx86, @"Microsoft Visual Studio 11.0\VC\vcvarsall.bat"), 11));

            yield return(new VcVarsBatFile(actions.PathCombine(programFilesx86, @"Microsoft Visual Studio 10.0\VC\vcvarsall.bat"), 10));
        }
 /// <summary>
 /// Enumerates all available tools.
 /// </summary>
 public static IEnumerable <VcVarsBatFile> VcVarsAllBatFiles(IBuildActions actions) =>
 GetCandidateVcVarsFiles(actions).Where(v => actions.FileExists(v.Path));
Beispiel #3
0
        /// <summary>
        /// Find all the relevant files and picks the best
        /// solution file and tools.
        /// </summary>
        /// <param name="options">The command line options.</param>
        public Autobuilder(IBuildActions actions, AutobuildOptions options)
        {
            Actions = actions;
            Options = options;

            pathsLazy = new Lazy <IEnumerable <string> >(() =>
            {
                var files = new List <string>();
                FindFiles(options.RootDirectory, options.SearchDepth, files);
                return(files.
                       OrderBy(s => s.Count(c => c == Path.DirectorySeparatorChar)).
                       ThenBy(s => Path.GetFileName(s).Length).
                       ToArray());
            });

            solutionsToBuildLazy = new Lazy <IList <ISolution> >(() =>
            {
                if (options.Solution.Any())
                {
                    var ret = new List <ISolution>();
                    foreach (var solution in options.Solution)
                    {
                        if (actions.FileExists(solution))
                        {
                            ret.Add(new Solution(this, solution));
                        }
                        else
                        {
                            Log(Severity.Error, "The specified solution file {0} was not found", solution);
                        }
                    }
                    return(ret);
                }

                var solutions = GetExtensions(".sln").
                                Select(s => new Solution(this, s)).
                                Where(s => s.ProjectCount > 0).
                                OrderByDescending(s => s.ProjectCount).
                                ThenBy(s => s.Path.Length).
                                ToArray();

                foreach (var sln in solutions)
                {
                    Log(Severity.Info, $"Found {sln.Path} with {sln.ProjectCount} {this.Options.Language} projects, version {sln.ToolsVersion}, config {string.Join(" ", sln.Configurations.Select(c => c.FullName))}");
                }

                return(new List <ISolution>(options.AllSolutions ?
                                            solutions :
                                            solutions.Take(1)));
            });

            SemmleDist = Actions.GetEnvironmentVariable("SEMMLE_DIST");

            SemmleJavaHome = Actions.GetEnvironmentVariable("SEMMLE_JAVA_HOME");

            SemmlePlatformTools = Actions.GetEnvironmentVariable("SEMMLE_PLATFORM_TOOLS");

            if (SemmleDist == null)
            {
                Log(Severity.Error, "The environment variable SEMMLE_DIST has not been set.");
            }
        }