コード例 #1
0
        public BuildEnvironment(BuildEnvironmentMode mode, string currentMSBuildExePath, bool runningTests, bool runningInVisualStudio, string visualStudioPath)
        {
            FileInfo      currentMSBuildExeFile = null;
            DirectoryInfo currentToolsDirectory = null;

            Mode                             = mode;
            RunningTests                     = runningTests;
            RunningInVisualStudio            = runningInVisualStudio;
            CurrentMSBuildExePath            = currentMSBuildExePath;
            VisualStudioInstallRootDirectory = visualStudioPath;

            if (!string.IsNullOrEmpty(currentMSBuildExePath))
            {
                currentMSBuildExeFile = new FileInfo(currentMSBuildExePath);
                currentToolsDirectory = currentMSBuildExeFile.Directory;

                CurrentMSBuildToolsDirectory    = currentMSBuildExeFile.DirectoryName;
                CurrentMSBuildConfigurationFile = string.Concat(currentMSBuildExePath, ".config");
                MSBuildToolsDirectory32         = CurrentMSBuildToolsDirectory;
                MSBuildToolsDirectory64         = CurrentMSBuildToolsDirectory;
            }

            // We can't detect an environment, don't try to set other paths.
            if (mode == BuildEnvironmentMode.None || currentMSBuildExeFile == null || currentToolsDirectory == null)
            {
                return;
            }

            // Check to see if our current folder is 'amd64'
            bool runningInAmd64 = string.Equals(currentToolsDirectory.Name, "amd64", StringComparison.OrdinalIgnoreCase);

            var msBuildExeName = currentMSBuildExeFile.Name;
            var folderAbove    = currentToolsDirectory.Parent?.FullName;

            if (folderAbove != null)
            {
                // Calculate potential paths to other architecture MSBuild.exe
                var potentialAmd64FromX86 = FileUtilities.CombinePaths(CurrentMSBuildToolsDirectory, "amd64", msBuildExeName);
                var potentialX86FromAmd64 = Path.Combine(folderAbove, msBuildExeName);

                // Check for existence of an MSBuild file. Note this is not necessary in a VS installation where we always want to
                // assume the correct layout.
                var existsCheck = mode == BuildEnvironmentMode.VisualStudio ? new Func <string, bool>(_ => true) : File.Exists;

                // Running in amd64 folder and the X86 path is valid
                if (runningInAmd64 && existsCheck(potentialX86FromAmd64))
                {
                    MSBuildToolsDirectory32 = folderAbove;
                    MSBuildToolsDirectory64 = CurrentMSBuildToolsDirectory;
                }
                // Not running in amd64 folder and the amd64 path is valid
                else if (!runningInAmd64 && existsCheck(potentialAmd64FromX86))
                {
                    MSBuildToolsDirectory32 = CurrentMSBuildToolsDirectory;
                    MSBuildToolsDirectory64 = Path.Combine(CurrentMSBuildToolsDirectory, "amd64");
                }
            }

            MSBuildExtensionsPath = mode == BuildEnvironmentMode.VisualStudio
                ? Path.Combine(VisualStudioInstallRootDirectory, "MSBuild")
                : MSBuildToolsDirectory32;
        }
コード例 #2
0
 private static string GetMSBuildExeFromVsRoot(string visualStudioRoot)
 {
     return(FileUtilities.CombinePaths(visualStudioRoot, "MSBuild", CurrentToolsVersion, "Bin", "MSBuild.exe"));
 }