示例#1
0
        /// <summary>
        /// Gets the path of MSBuild for the specified version.
        /// </summary>
        public static string GetMSBuildPath(MSBuildSettings?settings)
        {
            if (settings?.MSBuildPath is string settingsPath)
            {
                return(settingsPath);
            }

            if (BuildEnvironment.IsMacOS())
            {
                const string msbuildPath = "/Library/Frameworks/Mono.framework/Versions/Current/Commands/msbuild";
                if (File.Exists(msbuildPath))
                {
                    return(msbuildPath);
                }
            }
            else if (BuildEnvironment.IsLinux())
            {
                const string msbuildPath = "/usr/bin/msbuild";
                if (File.Exists(msbuildPath))
                {
                    return(msbuildPath);
                }
            }
            else
            {
                var version  = settings?.Version ?? MSBuildVersion.VS2017;
                var platform = settings?.Platform ?? (BuildEnvironment.Is64Bit() ? MSBuildPlatform.X64 : MSBuildPlatform.X32);

                (string Year, string Version) getPathParts()
                {
                    if (version == MSBuildVersion.VS2017)
                    {
                        return("2017", "15.0");
                    }
                    else if (version == MSBuildVersion.VS2019)
                    {
                        return("2019", "Current");
                    }
                    else
                    {
                        throw new ArgumentException("Invalid version.", nameof(version));
                    }
                }

                var parts = getPathParts();
                foreach (var edition in new[] { "Enterprise", "Professional", "Community", "BuildTools", "Preview" })
                {
                    var msbuildPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
                                                   "Microsoft Visual Studio", parts.Year, edition, "MSBuild", parts.Version, "Bin", platform == MSBuildPlatform.X64 ? "amd64" : "", "MSBuild.exe");
                    if (File.Exists(msbuildPath))
                    {
                        return(msbuildPath);
                    }
                }
            }

            throw new InvalidOperationException("MSBuild not found.");
        }
示例#2
0
        /// <summary>
        /// Runs the specified .NET Framework command-line app.
        /// </summary>
        /// <param name="path">The path of the command-line app.</param>
        /// <param name="settings">The settings to use when running the app.</param>
        /// <remarks>On Linux and macOS, Mono is used to run the app.</remarks>
        public static int RunDotNetFrameworkApp(string path, AppRunnerSettings settings)
        {
            if (BuildEnvironment.IsUnix())
            {
                settings           = settings.Clone();
                settings.Arguments = new[] { path }.Concat(settings.Arguments ?? Enumerable.Empty <string>()).ToList();
                path = "mono";
            }

            return(RunApp(path, settings));
        }
示例#3
0
        /// <summary>
        /// Gets the path of MSBuild for the specified version.
        /// </summary>
        public static string GetMSBuildPath(MSBuildSettings?settings)
        {
            if (settings?.MSBuildPath is string settingsPath)
            {
                return(settingsPath);
            }

            if (BuildEnvironment.IsMacOS())
            {
                const string msbuildPath = "/Library/Frameworks/Mono.framework/Versions/Current/Commands/msbuild";
                if (File.Exists(msbuildPath))
                {
                    return(msbuildPath);
                }
            }
            else if (BuildEnvironment.IsLinux())
            {
                const string msbuildPath = "/usr/bin/msbuild";
                if (File.Exists(msbuildPath))
                {
                    return(msbuildPath);
                }
            }
            else
            {
                var version  = settings?.Version ?? MSBuildVersion.VS2017;
                var platform = settings?.Platform ?? (BuildEnvironment.Is64Bit() ? MSBuildPlatform.X64 : MSBuildPlatform.X32);

                var(pathYear, pathVersion) = GetPathParts();
                foreach (var edition in new[] { "Enterprise", "Professional", "Community", "BuildTools", "Preview" })
                {
                    var msbuildPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
                                                   "Microsoft Visual Studio", pathYear, edition, "MSBuild", pathVersion, "Bin", platform == MSBuildPlatform.X64 ? "amd64" : "", "MSBuild.exe");
                    if (File.Exists(msbuildPath))
                    {
                        return(msbuildPath);
                    }
                }

                (string Year, string Version) GetPathParts()
                {
                    return(version switch
                    {
                        MSBuildVersion.VS2017 => ("2017", "15.0"),
                        MSBuildVersion.VS2019 => ("2019", "Current"),
                        _ => throw new BuildException($"Unexpected MSBuildVersion: {version}"),
                    });