示例#1
0
        private void GetVisualStudio(KoreBuildSettings.VisualStudioToolset vsToolset)
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                if ((vsToolset.Required & ~KoreBuildSettings.RequiredPlatforms.Windows) != 0)
                {
                    Log.LogError("Visual Studio is not available on non-Windows. Change korebuild.json to 'required: [\"windows\"]'.");
                }
                else
                {
                    Log.LogMessage(MessageImportance.Low, "Skipping Visual Studio verification on non-Windows platforms.");
                }
                return;
            }

            var vs = VsWhere.FindLatestCompatibleInstallation(vsToolset, Log);

            if (vs == null)
            {
                if (vsToolset.Required != KoreBuildSettings.RequiredPlatforms.None)
                {
                    Log.LogError($"Could not find an installation of Visual Studio that satisifies the specified requirements in '{ConfigFile}'. " +
                                 "Execute `./run.ps1 install vs` to update or install the current VS installation. " +
                                 "See https://docs.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-community for more details on workloads.");
                }
                return;
            }

            Log.LogMessage(MessageImportance.High, "Using {0} from {1}", vs.DisplayName, vs.InstallationPath);

            VisualStudioMSBuildx86Path = vs.GetMSBuildx86SubPath();
            VisualStudioMSBuildx64Path = vs.GetMSBuildx64SubPath();
        }
        public override bool Execute()
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Log.LogError("Visual Studio cannot be found on non-Windows platforms");
                return(false);
            }

            VsInstallation vs;

            if (!string.IsNullOrEmpty(ConfigFile))
            {
                if (!File.Exists(ConfigFile))
                {
                    Log.LogError($"Could not load the korebuild config file from '{ConfigFile}'");
                    return(false);
                }

                var settings  = KoreBuildSettings.Load(ConfigFile);
                var vsToolset = settings.Toolsets?.OfType <KoreBuildSettings.VisualStudioToolset>().FirstOrDefault();
                if (vsToolset != null)
                {
                    vs = VsWhere.FindLatestCompatibleInstallation(vsToolset, Log);
                    if (vs == null)
                    {
                        Log.LogError($"Could not find an installation of Visual Studio that satisifies the specified requirements in {ConfigFile}. " +
                                     "See https://docs.microsoft.com/en-us/visualstudio/install/workload-component-id-vs-community for more details on any missing components.");
                        return(false);
                    }
                }
                else
                {
                    vs = VsWhere.FindLatestInstallation(includePrerelease: true, log: Log);
                }
            }
            else
            {
                vs = VsWhere.FindLatestInstallation(includePrerelease: true, log: Log);
            }

            if (vs == null)
            {
                Log.LogError($"Could not find any installation of Visual Studio.");
                return(false);
            }

            Log.LogMessage(MessageImportance.Normal, "Found {0} in {1}", vs.DisplayName, vs.InstallationPath);

            InstallationBasePath = vs.InstallationPath;
            MSBuildx86Path       = vs.GetMSBuildx86SubPath();
            MSBuildx64Path       = vs.GetMSBuildx64SubPath();

            return(!Log.HasLoggedErrors);
        }
示例#3
0
        public void TryGetVersion_ReturnsFalseWhenNoVersionsProvided()
        {
            // Arrange
            var toolset = new KoreBuildSettings.VisualStudioToolset();

            // Act
            var result = VsWhere.TryGetVersion(toolset, out var version);

            // Assert
            Assert.False(result);
            Assert.Null(version);
        }
示例#4
0
        private async Task InstallVsComponents(KoreBuildSettings.VisualStudioToolset vsToolset)
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                if ((vsToolset.Required & ~KoreBuildSettings.RequiredPlatforms.Windows) != 0)
                {
                    Log.LogError("Visual Studio is not available on non-Windows. Change korebuild.json to 'required: [\"windows\"]'.");
                }
                else
                {
                    Log.LogMessage(MessageImportance.Low, "Skipping Visual Studio verification on non-Windows platforms.");
                }
                return;
            }

            // Update the vs installation based on the product version specified.
            var vs = VsWhere.FindLatestInstallation(includePrerelease: true, vsProductVersion: VSProductVersionType, log: Log);

            if (vs != null)
            {
                Log.LogMessage($"Found vs installation located at {vs.InstallationPath}");
            }
            else
            {
                Log.LogMessage($"No vs installation found.");
            }

            var vsExePath = await VsInstallerHelper.DownloadVsExe(Log, VSProductVersionType);

            var vsJsonFilePath = VsInstallerHelper.CreateVsFileFromRequiredToolset(vsToolset, Log, VSProductVersionType);

            var args = GetVisualStudioArgs(vs, vsJsonFilePath);

            StartVsExe(vsExePath, args);

            // Cleanup temp files created.
            try
            {
                File.Delete(vsExePath);
                File.Delete(vsJsonFilePath);
            }
            catch (IOException ioe)
            {
                Log.LogWarning($"Could not delete vs installation files in temp directory: {ioe.Message}.");
            }

            return;
        }
示例#5
0
        public void TryGetVersion_ReturnsVersionRange()
        {
            // Arrange
            var expectedVersion = "[15.0,16.0)";
            var toolset         = new KoreBuildSettings.VisualStudioToolset()
            {
                VersionRange = expectedVersion,
            };

            // Act
            var result = VsWhere.TryGetVersion(toolset, out var version);

            // Assert
            Assert.True(result);
            Assert.Equal(expectedVersion, version);
        }
        public override bool Execute()
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Log.LogError("Full MSBuild is not available on non-Windows.");
                return(false);
            }

            var vs = VsWhere.FindLatestInstallation(includePrerelease: true, Log);

            if (vs == null)
            {
                Log.LogError($"Could not find an installation of Visual Studio.");
                return(false);
            }

            MSBuildx86Path = vs.GetMSBuildx86SubPath();

            return(!Log.HasLoggedErrors);
        }