Пример #1
0
        public BuildEnvironment(BuildEnvironmentMode mode, string currrentMSBuildExePath, bool runningTests, bool runningInVisualStudio, string visualStudioPath)
        {
            Mode                  = mode;
            RunningTests          = runningTests;
            RunningInVisualStudio = runningInVisualStudio;

            CurrentMSBuildExePath           = currrentMSBuildExePath;
            CurrentMSBuildToolsDirectory    = Path.GetDirectoryName(currrentMSBuildExePath);
            CurrentMSBuildConfigurationFile = string.Concat(currrentMSBuildExePath, ".config");

            VisualStudioInstallRootDirectory = visualStudioPath;

            if (mode == BuildEnvironmentMode.VisualStudio)
            {
                var isAmd64 = FileUtilities.EnsureNoTrailingSlash(CurrentMSBuildToolsDirectory)
                              .EndsWith("amd64", StringComparison.OrdinalIgnoreCase);

                if (isAmd64)
                {
                    MSBuildToolsDirectory32 = FileUtilities.GetFolderAbove(CurrentMSBuildToolsDirectory);
                    MSBuildToolsDirectory64 = CurrentMSBuildToolsDirectory;
                }
                else
                {
                    MSBuildToolsDirectory32 = CurrentMSBuildToolsDirectory;
                    MSBuildToolsDirectory64 = Path.Combine(CurrentMSBuildToolsDirectory, "amd64");
                }
            }
            else
            {
                MSBuildToolsDirectory32 = CurrentMSBuildToolsDirectory;
                MSBuildToolsDirectory64 = CurrentMSBuildToolsDirectory;
            }

            MSBuildExtensionsPath = mode == BuildEnvironmentMode.VisualStudio
                ? Path.Combine(VisualStudioInstallRootDirectory, "MSBuild")
                : CurrentMSBuildToolsDirectory;
        }
Пример #2
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;
        }
Пример #3
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 !NO_FRAMEWORK_IVT
            Framework.BuildEnvironmentState.s_runningTests          = runningTests;
            Framework.BuildEnvironmentState.s_runningInVisualStudio = runningInVisualStudio;
#endif

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

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

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

            var msBuildExeName = currentMSBuildExeFile.Name;

            if (mode == BuildEnvironmentMode.VisualStudio)
            {
                // In Visual Studio, the entry-point MSBuild.exe is often from an arch-specific subfolder
                MSBuildToolsDirectoryRoot = NativeMethodsShared.ProcessorArchitecture switch
                {
                    NativeMethodsShared.ProcessorArchitectures.X86 => CurrentMSBuildToolsDirectory,
                    NativeMethodsShared.ProcessorArchitectures.X64 or NativeMethodsShared.ProcessorArchitectures.ARM64
                    => currentToolsDirectory.Parent?.FullName,
                    _ => throw new InternalErrorException("Unknown processor architecture " + NativeMethodsShared.ProcessorArchitecture),
                };
            }
            else
            {
                // In the .NET SDK, there's one copy of MSBuild.dll and it's in the root folder.
                MSBuildToolsDirectoryRoot = CurrentMSBuildToolsDirectory;
            }

            if (mode == BuildEnvironmentMode.VisualStudio && MSBuildToolsDirectoryRoot != null)
            {
                // Calculate potential paths to other architecture MSBuild.exe
                var potentialAmd64FromX86 = FileUtilities.CombinePaths(MSBuildToolsDirectoryRoot, "amd64", msBuildExeName);
                var potentialARM64FromX86 = FileUtilities.CombinePaths(MSBuildToolsDirectoryRoot, "arm64", 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;

                MSBuildToolsDirectory32    = MSBuildToolsDirectoryRoot;
                MSBuildToolsDirectory64    = Path.Combine(MSBuildToolsDirectoryRoot, "amd64");
                MSBuildToolsDirectoryArm64 = File.Exists(potentialARM64FromX86) ? Path.Combine(MSBuildToolsDirectoryRoot, "arm64") : null;
            }

            MSBuildExtensionsPath = mode == BuildEnvironmentMode.VisualStudio
                ? Path.Combine(VisualStudioInstallRootDirectory, "MSBuild")
                : MSBuildToolsDirectory32;
        }