Exemplo n.º 1
0
        private static BuildScript WithDotNet(Autobuilder builder, Func <string?, IDictionary <string, string>?, BuildScript> f)
        {
            var installDir    = builder.Actions.PathCombine(builder.Options.RootDirectory, ".dotnet");
            var installScript = DownloadDotNet(builder, installDir);

            return(BuildScript.Bind(installScript, installed =>
            {
                Dictionary <string, string>?env;
                if (installed == 0)
                {
                    // The installation succeeded, so use the newly installed .NET Core
                    var path = builder.Actions.GetEnvironmentVariable("PATH");
                    var delim = builder.Actions.IsWindows() ? ";" : ":";
                    env = new Dictionary <string, string> {
                        { "DOTNET_MULTILEVEL_LOOKUP", "false" },     // prevent look up of other .NET Core SDKs
                        { "DOTNET_SKIP_FIRST_TIME_EXPERIENCE", "true" },
                        { "PATH", installDir + delim + path }
                    };
                }
                else
                {
                    installDir = null;
                    env = null;
                }

                if (env is null)
                {
                    env = new Dictionary <string, string>();
                }
                env.Add("UseSharedCompilation", "false");
                return f(installDir, env);
            }));
        }
Exemplo n.º 2
0
        private static BuildScript WithDotNet(Autobuilder builder, Func <string?, IDictionary <string, string>?, bool, BuildScript> f)
        {
            var installDir    = builder.Actions.PathCombine(builder.Options.RootDirectory, ".dotnet");
            var installScript = DownloadDotNet(builder, installDir);

            return(BuildScript.Bind(installScript, installed =>
            {
                Dictionary <string, string>?env;
                if (installed == 0)
                {
                    // The installation succeeded, so use the newly installed .NET Core
                    var path = builder.Actions.GetEnvironmentVariable("PATH");
                    var delim = builder.Actions.IsWindows() ? ";" : ":";
                    env = new Dictionary <string, string> {
                        { "DOTNET_MULTILEVEL_LOOKUP", "false" },     // prevent look up of other .NET Core SDKs
                        { "DOTNET_SKIP_FIRST_TIME_EXPERIENCE", "true" },
                        { "PATH", installDir + delim + path }
                    };
                }
                else
                {
                    installDir = null;
                    env = null;
                }

                // The CLR tracer is always compatible on Windows
                if (builder.Actions.IsWindows())
                {
                    return f(installDir, env, true);
                }

                // The CLR tracer is only compatible on .NET Core >= 3 on Linux and macOS (see
                // https://github.com/dotnet/coreclr/issues/19622)
                return BuildScript.Bind(GetInstalledRuntimesScript(builder.Actions, installDir, env), (runtimes, runtimesRet) =>
                {
                    var compatibleClr = false;
                    if (runtimesRet == 0)
                    {
                        var minimumVersion = new Version(3, 0);
                        var regex = new Regex(@"Microsoft\.NETCore\.App (\d\.\d\.\d)");
                        compatibleClr = runtimes
                                        .Select(runtime => regex.Match(runtime))
                                        .Where(m => m.Success)
                                        .Select(m => m.Groups[1].Value)
                                        .Any(m => Version.TryParse(m, out var v) && v >= minimumVersion);
                    }

                    if (!compatibleClr)
                    {
                        if (env is null)
                        {
                            env = new Dictionary <string, string>();
                        }
                        env.Add("UseSharedCompilation", "false");
                    }

                    return f(installDir, env, compatibleClr);
                });
            }));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Returns a script for downloading a specific .NET Core SDK version, if the
        /// version is not already installed.
        ///
        /// See https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script.
        /// </summary>
        private static BuildScript DownloadDotNetVersion(Autobuilder builder, string path, string version)
        {
            return(BuildScript.Bind(GetInstalledSdksScript(builder.Actions), (sdks, sdksRet) =>
            {
                if (sdksRet == 0 && sdks.Count == 1 && sdks[0].StartsWith(version + " ", StringComparison.Ordinal))
                {
                    // The requested SDK is already installed (and no other SDKs are installed), so
                    // no need to reinstall
                    return BuildScript.Failure;
                }

                builder.Log(Severity.Info, "Attempting to download .NET Core {0}", version);

                if (builder.Actions.IsWindows())
                {
                    var psCommand = $"[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; &([scriptblock]::Create((Invoke-WebRequest -UseBasicParsing 'https://dot.net/v1/dotnet-install.ps1'))) -Version {version} -InstallDir {path}";

                    BuildScript GetInstall(string pwsh) =>
                    new CommandBuilder(builder.Actions).
                    RunCommand(pwsh).
                    Argument("-NoProfile").
                    Argument("-ExecutionPolicy").
                    Argument("unrestricted").
                    Argument("-Command").
                    Argument("\"" + psCommand + "\"").
                    Script;

                    return GetInstall("pwsh") | GetInstall("powershell");
                }
                else
                {
                    var downloadDotNetInstallSh = BuildScript.DownloadFile(
                        "https://dot.net/v1/dotnet-install.sh",
                        "dotnet-install.sh",
                        e => builder.Log(Severity.Warning, $"Failed to download 'dotnet-install.sh': {e.Message}"));

                    var chmod = new CommandBuilder(builder.Actions).
                                RunCommand("chmod").
                                Argument("u+x").
                                Argument("dotnet-install.sh");

                    var install = new CommandBuilder(builder.Actions).
                                  RunCommand("./dotnet-install.sh").
                                  Argument("--channel").
                                  Argument("release").
                                  Argument("--version").
                                  Argument(version).
                                  Argument("--install-dir").
                                  Argument(path);

                    var removeScript = new CommandBuilder(builder.Actions).
                                       RunCommand("rm").
                                       Argument("dotnet-install.sh");

                    return downloadDotNetInstallSh & chmod.Script & install.Script & BuildScript.Try(removeScript.Script);
                }
            }));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns a script for downloading a specific .NET Core SDK version, if the
        /// version is not already installed.
        ///
        /// See https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script.
        /// </summary>
        private static BuildScript DownloadDotNetVersion(Autobuilder builder, string path, string version)
        {
            return(BuildScript.Bind(GetInstalledSdksScript(builder.Actions), (sdks, sdksRet) =>
            {
                if (sdksRet == 0 && sdks.Count == 1 && sdks[0].StartsWith(version + " ", StringComparison.Ordinal))
                {
                    // The requested SDK is already installed (and no other SDKs are installed), so
                    // no need to reinstall
                    return BuildScript.Failure;
                }

                builder.Log(Severity.Info, "Attempting to download .NET Core {0}", version);

                if (builder.Actions.IsWindows())
                {
                    var psScript = @"param([string]$Version, [string]$InstallDir)

add-type @""
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy
{
    public bool CheckValidationResult(ServicePoint srvPoint, X509Certificate certificate, WebRequest request, int certificateProblem)
    {
        return true;
    }
}
""@
$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
$Script = Invoke-WebRequest -useb 'https://dot.net/v1/dotnet-install.ps1'

$arguments = @{
  Channel = 'release'
  Version = $Version
  InstallDir = $InstallDir
}

$ScriptBlock = [scriptblock]::create("".{$($Script)} $(&{$args} @arguments)"")

Invoke-Command -ScriptBlock $ScriptBlock";
                    var psScriptFile = builder.Actions.PathCombine(builder.Options.RootDirectory, "install-dotnet.ps1");
                    builder.Actions.WriteAllText(psScriptFile, psScript);

                    var install = new CommandBuilder(builder.Actions).
                                  RunCommand("powershell").
                                  Argument("-NoProfile").
                                  Argument("-ExecutionPolicy").
                                  Argument("unrestricted").
                                  Argument("-file").
                                  Argument(psScriptFile).
                                  Argument("-Version").
                                  Argument(version).
                                  Argument("-InstallDir").
                                  Argument(path);

                    var removeScript = new CommandBuilder(builder.Actions).
                                       RunCommand("del").
                                       Argument(psScriptFile);

                    return install.Script & BuildScript.Try(removeScript.Script);
                }
                else
                {
                    var downloadDotNetInstallSh = BuildScript.DownloadFile(
                        "https://dot.net/v1/dotnet-install.sh",
                        "dotnet-install.sh",
                        e => builder.Log(Severity.Warning, $"Failed to download 'dotnet-install.sh': {e.Message}"));

                    var chmod = new CommandBuilder(builder.Actions).
                                RunCommand("chmod").
                                Argument("u+x").
                                Argument("dotnet-install.sh");

                    var install = new CommandBuilder(builder.Actions).
                                  RunCommand("./dotnet-install.sh").
                                  Argument("--channel").
                                  Argument("release").
                                  Argument("--version").
                                  Argument(version).
                                  Argument("--install-dir").
                                  Argument(path);

                    var removeScript = new CommandBuilder(builder.Actions).
                                       RunCommand("rm").
                                       Argument("dotnet-install.sh");

                    return downloadDotNetInstallSh & chmod.Script & install.Script & BuildScript.Try(removeScript.Script);
                }
            }));
        }