Пример #1
0
        public static VsInstallation FindLatestCompatibleInstallation(KoreBuildSettings.VisualStudioToolset toolset, TaskLoggingHelper log)
        {
            var args = new List <string> {
                "-latest"
            };

            if (toolset.IncludePrerelease)
            {
                args.Add("-prerelease");
            }

            if (TryGetVersion(toolset, out var version))
            {
                args.Add("-version");
                args.Add(version);
            }

            if (toolset.RequiredWorkloads != null)
            {
                foreach (var workload in toolset.RequiredWorkloads)
                {
                    args.Add("-requires");
                    args.Add(workload);
                }
            }

            return(GetInstallations(args, log).FirstOrDefault());
        }
Пример #2
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();
        }
Пример #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);
        }
Пример #6
0
        // Internal for testing
        internal static bool TryGetVersion(KoreBuildSettings.VisualStudioToolset toolset, out string version)
        {
            if (!string.IsNullOrEmpty(toolset.VersionRange))
            {
                // This is the same as MinVersion but the name indicates that a user can specify more than just
                // a min version. For example: [15.0,16.0) will find versions 15.*.
                version = toolset.VersionRange;
                return(true);
            }

            if (!string.IsNullOrEmpty(toolset.MinVersion))
            {
                // Here for back compatibility.
                version = toolset.MinVersion;
                return(true);
            }

            version = null;
            return(false);
        }
Пример #7
0
        public static string CreateVsFileFromRequiredToolset(KoreBuildSettings.VisualStudioToolset vsToolset, TaskLoggingHelper log, string vsProductType)
        {
            var vsFile = new VsJsonFile
            {
                ChannelUri         = "https://aka.ms/vs/15/release/channel",
                ChannelId          = "VisualStudio.15.Release",
                ProductId          = $"Microsoft.VisualStudio.Product.{vsProductType}",
                IncludeRecommended = false,
                AddProductLang     = new List <string>
                {
                    "en-US"
                },
                Add = new List <string>(vsToolset.RequiredWorkloads)
            };

            var tempFile = Path.Combine(Path.GetTempPath(), $"vs_{vsProductType}.json");

            var json = JsonConvert.SerializeObject(vsFile);

            File.WriteAllText(tempFile, json);

            return(tempFile);
        }