public override IEnumerable <Checkup> Contribute(Manifest.Manifest manifest, SharedState sharedState)
        {
            var sdks = manifest?.Check?.DotNet?.Sdks;

            if (sdks?.Any() ?? false)
            {
                foreach (var sdk in sdks)
                {
                    var workloads = sdk?.Workloads?.ToArray() ?? Array.Empty <DotNetWorkload>();
                    var packs     = sdk?.Packs?.ToArray() ?? Array.Empty <DotNetSdkPack>();
                    var pkgSrcs   = sdk?.PackageSources?.ToArray() ?? Array.Empty <string>();

                    string sdkVersion;
                    if (!sharedState.TryGetEnvironmentVariable("DOTNET_SDK_VERSION", out sdkVersion))
                    {
                        sdkVersion = sdk.Version;
                    }

                    if (sdk.Workloads?.Any() ?? false)
                    {
                        yield return(new DotNetWorkloadsCheckup(sharedState, sdkVersion, workloads, pkgSrcs));
                    }

                    // Always generate a packs check even if no packs, since the workloads may dynamically
                    // discover packs required and register them with the SharedState
                    yield return(new DotNetPacksCheckup(sharedState, sdkVersion, packs, pkgSrcs));
                }
            }
        }
Esempio n. 2
0
        public override Task <DiagnosticResult> Examine(SharedState history)
        {
            if (!history.TryGetEnvironmentVariable("DOTNET_SDK_VERSION", out var sdkVersion))
            {
                sdkVersion = SdkVersion;
            }

            var workloadManager = new DotNetWorkloadManager(SdkRoot, sdkVersion, NuGetPackageSources);

            //var installedWorkloads = workloadManager.GetInstalledWorkloads();

            // This is a bit of a hack where we manually check the sdk-manifests/{SDK_VERSION}/* folders
            // for installed workloads, and then go manually parse the manifest json
            // as well as look for a .nuspec file from the extracted nupkg when it was installed
            // the nuspec file contains the version we actually care about for now since the manifest json
            // has a long number which is meaningless right now and will eventually be changed to a string
            // when that happens we can use the actual resolver's method to get installed workload info
            var installedPackageWorkloads = workloadManager.GetInstalledWorkloads();

            var missingWorkloads = new List <Manifest.DotNetWorkload>();

            foreach (var rp in RequiredWorkloads)
            {
                if (!NuGetVersion.TryParse(rp.Version, out var rpVersion))
                {
                    rpVersion = new NuGetVersion(0, 0, 0);
                }

                // TODO: Eventually check actual workload resolver api for installed workloads and
                // compare the manifest version once it has a string in it
                if (!installedPackageWorkloads.Any(ip => ip.id.Equals(rp.Id, StringComparison.OrdinalIgnoreCase) && NuGetVersion.TryParse(ip.version, out var ipVersion) && ipVersion == rpVersion))
                {
                    ReportStatus($"{rp.Id} ({rp.PackageId} : {rp.Version}) not installed.", Status.Error);
                    missingWorkloads.Add(rp);
                }
        public override async Task <DiagnosticResult> Examine(SharedState history)
        {
            if (!history.TryGetEnvironmentVariable("DOTNET_SDK_VERSION", out var sdkVersion))
            {
                sdkVersion = SdkVersion;
            }

            var force = history.TryGetEnvironmentVariable("DOTNET_FORCE", out var forceDotNet) &&
                        (forceDotNet?.Equals("true", StringComparison.OrdinalIgnoreCase) ?? false) &&
                        !wasForceRunAlready;

            // Don't allow multiple force runs, just the first
            if (force)
            {
                wasForceRunAlready = true;
            }

            var workloadManager = new DotNetWorkloadManager(SdkRoot, sdkVersion, NuGetPackageSources);

            var installedPackageWorkloads = workloadManager.GetInstalledWorkloads();

            var missingWorkloads = new List <Manifest.DotNetWorkload>();

            foreach (var rp in RequiredWorkloads)
            {
                if (!NuGetVersion.TryParse(rp.Version, out var rpVersion))
                {
                    rpVersion = new NuGetVersion(0, 0, 0);
                }

                // TODO: Eventually check actual workload resolver api for installed workloads and
                // compare the manifest version once it has a string in it
                if (!installedPackageWorkloads.Any(ip => ip.id.Equals(rp.Id, StringComparison.OrdinalIgnoreCase) && NuGetVersion.TryParse(ip.version, out var ipVersion) && ipVersion == rpVersion))
                {
                    ReportStatus($"{rp.Id} ({rp.PackageId} : {rp.Version}) not installed.", Status.Error);
                    missingWorkloads.Add(rp);
                }
Esempio n. 4
0
        public override Task <DiagnosticResult> Examine(SharedState history)
        {
            string sdkVersion;

            if (!history.TryGetEnvironmentVariable("DOTNET_SDK_VERSION", out sdkVersion))
            {
                sdkVersion = SdkVersion;
            }

            var workloadManager = new DotNetWorkloadManager(SdkRoot, sdkVersion, NuGetPackageSources);

            var sdkPacks = workloadManager.GetAllInstalledWorkloadPacks();

            var missingPacks = new List <Manifest.DotNetSdkPack>();

            foreach (var rp in GetAllRequiredPacks(history))
            {
                Util.Log($"Looking for pack: {rp.Id} ({rp.Version})");

                if (!sdkPacks.Any(sp => sp.Id == rp.Id && sp.Version == rp.Version) &&
                    !workloadManager.TemplateExistsOnDisk(rp.Id, rp.Version, rp.PackKind, rp.TemplateShortName) &&
                    !workloadManager.PackExistsOnDisk(rp.Id, rp.Version))
                {
                    ReportStatus($"{rp.Id} ({rp.Version}) not installed.", Status.Warning);
                    missingPacks.Add(rp);
                }
                else
                {
                    ReportStatus($"{rp.Id} ({rp.Version}) installed.", Status.Ok);
                }
            }

            if (!missingPacks.Any())
            {
                return(Task.FromResult(DiagnosticResult.Ok(this)));
            }

            var remedies = missingPacks
                           .Select(ms => new DotNetPackInstallSolution(SdkRoot, sdkVersion, ms, NuGetPackageSources));

            return(Task.FromResult(new DiagnosticResult(
                                       Status.Error,
                                       this,
                                       new Suggestion("Install Missing SDK Packs",
                                                      remedies.ToArray()))));
        }
Esempio n. 5
0
        public override async Task Implement(SharedState sharedState, CancellationToken cancellationToken)
        {
            await base.Implement(sharedState, cancellationToken);

            string sdkRoot = default;

            if (sharedState != null && sharedState.TryGetEnvironmentVariable("DOTNET_ROOT", out var envSdkRoot))
            {
                if (Directory.Exists(envSdkRoot))
                {
                    sdkRoot = envSdkRoot;
                }
            }

            if (string.IsNullOrEmpty(sdkRoot))
            {
                sdkRoot = Util.IsWindows
                                        ? Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "dotnet")
                                        : Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".dotnet");
            }

            var scriptUrl  = Util.IsWindows ? installScriptPwsh : installScriptBash;
            var scriptPath = Path.Combine(Path.GetTempPath(), Util.IsWindows ? "dotnet-install.ps1" : "dotnet-install.sh");

            Util.Log($"Downloading dotnet-install script: {scriptUrl}");

            var http = new HttpClient();
            var data = await http.GetStringAsync(scriptUrl);

            File.WriteAllText(scriptPath, data);

            var exe  = Util.IsWindows ? "powershell" : "sh";
            var args = Util.IsWindows
                                        ? $"{scriptPath} -InstallDir {sdkRoot} -Version {Version}"
                                        : $"{scriptPath} --install-dir {sdkRoot} --version {Version}";

            Util.Log($"Executing dotnet-install script...");
            Util.Log($"\t{exe} {args}");

            // Launch the process
            var p = new ShellProcessRunner(new ShellProcessRunnerOptions(exe, args));

            p.WaitForExit();
        }
        public override Task <DiagnosticResult> Examine(SharedState history)
        {
            var dotnet  = new DotNetSdk(history);
            var sdkRoot = dotnet.DotNetSdkLocation.FullName;

            if (history.TryGetEnvironmentVariable("DOTNET_SDK_VERSION", out var sdkVersion))
            {
                // HACK  / WORKAROUND
                // Workload manifest specs changed between p4/p5 and with that came manifest folder name changes
                // The problem is we can be left with duplicate workload manifests but in different
                // folder names and the resolver can't handle that.
                // This will identify a block list of old workload folders and delete them if the dotnet version
                // is -preview.5 or newer of the sdk and a different block list if -preview.4 or older
                if (NuGetVersion.TryParse(sdkVersion, out var parsedSdkVersion))
                {
                    DeleteBlockedWorkloads(
                        sdkRoot,
                        $"{parsedSdkVersion.Major}.{parsedSdkVersion.Minor}.{parsedSdkVersion.Patch}",
                        parsedSdkVersion >= new NuGetVersion("6.0.100-preview.5")
                                                ? new[] {
                        "Microsoft.NET.Workload.Android",
                        "Microsoft.NET.Workload.BlazorWebAssembly",
                        "Microsoft.NET.Workload.iOS",
                        "Microsoft.NET.Workload.MacCatalyst",
                        "Microsoft.NET.Workload.macOS",
                        "Microsoft.NET.Workload.tvOS"
                    }
                                                : new[] {
                        "Microsoft.NET.Sdk.Android",
                        "Microsoft.NET.Sdk.iOS",
                        "Microsoft.NET.Sdk.MacCatalyst",
                        "Microsoft.NET.Sdk.macOS",
                        "Microsoft.NET.Sdk.tvOS",
                        "Microsoft.NET.Workload.Mono.ToolChain"
                    });
                }
            }

            return(Task.FromResult(DiagnosticResult.Ok(this)));
        }
Esempio n. 7
0
        public override IEnumerable <Checkup> Contribute(Manifest.Manifest manifest, SharedState sharedState)
        {
            var sdks = manifest?.Check?.DotNet?.Sdks;

            if (sdks?.Any() ?? false)
            {
                foreach (var sdk in sdks)
                {
                    var workloads = sdk?.Workloads?.ToArray() ?? Array.Empty <DotNetWorkload>();
                    var pkgSrcs   = sdk?.PackageSources?.ToArray() ?? Array.Empty <string>();

                    string sdkVersion;
                    if (!sharedState.TryGetEnvironmentVariable("DOTNET_SDK_VERSION", out sdkVersion))
                    {
                        sdkVersion = sdk.Version;
                    }

                    if (sdk.Workloads?.Any() ?? false)
                    {
                        yield return(new DotNetWorkloadsCheckup(sharedState, sdkVersion, workloads, pkgSrcs));
                    }
                }
            }
        }
Esempio n. 8
0
        public DotNetSdk(SharedState sharedState)
        {
            KnownDotnetLocations = Util.Platform switch
            {
                Platform.Windows => new string[]
                {
                    Path.Combine(
                        Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
                        "dotnet",
                        DotNetExeName),
                    Path.Combine(
                        Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
                        "dotnet",
                        DotNetExeName),
                },
                Platform.OSX => new string[]
                {
                    "/usr/local/share/dotnet/dotnet",
                },
                Platform.Linux => new string[]
                {
                    // /home/user/share/dotnet/dotnet
                    Path.Combine(
                        Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
                        "share",
                        "dotnet",
                        DotNetExeName)
                },
                _ => new string[] { }
            };

            string sdkRoot = null;

            if (sharedState != null && sharedState.TryGetEnvironmentVariable("DOTNET_ROOT", out var envSdkRoot))
            {
                if (Directory.Exists(envSdkRoot))
                {
                    sdkRoot = envSdkRoot;
                }
            }

            if (string.IsNullOrEmpty(sdkRoot) || !Directory.Exists(sdkRoot))
            {
                sdkRoot = Microsoft.DotNet.NativeWrapper.EnvironmentProvider.GetDotnetExeDirectory();
            }

            if (string.IsNullOrEmpty(sdkRoot) || !Directory.Exists(sdkRoot))
            {
                var l = FindDotNetLocations();
                if (l != default)
                {
                    sdkRoot = l.sdkDir.FullName;
                }
            }

            sharedState.SetEnvironmentVariable("DOTNET_ROOT", sdkRoot);

            // First try and use the actual resolver logic
            DotNetSdkLocation = new DirectoryInfo(sdkRoot);
            DotNetExeLocation = new FileInfo(Path.Combine(DotNetSdkLocation.FullName, DotNetExeName));
        }
        public override Task <DiagnosticResult> Examine(SharedState history)
        {
            string sdkVersion;

            if (!history.TryGetEnvironmentVariable("DOTNET_SDK_VERSION", out sdkVersion))
            {
                sdkVersion = SdkVersion;
            }

            var workloadManager = new DotNetWorkloadManager(SdkRoot, sdkVersion, NuGetPackageSources);

            var installedWorkloads        = workloadManager.GetInstalledWorkloads();
            var installedPackageWorkloads = workloadManager.GetInstalledWorkloadNuGetPackages();

            var missingWorkloads = new List <Manifest.DotNetWorkload>();

            var requiredPacks = new List <WorkloadResolver.PackInfo>();

            foreach (var rp in RequiredWorkloads)
            {
                NuGetVersion rpVersion;
                if (!NuGetVersion.TryParse(rp.Version, out rpVersion))
                {
                    rpVersion = new NuGetVersion(0, 0, 0);
                }

                if (!installedPackageWorkloads.Any(sp => sp.packageId.Equals(rp.PackageId, StringComparison.OrdinalIgnoreCase) && sp.packageVersion == rpVersion) ||
                    !installedWorkloads.Any(sp => sp.id.Equals(rp.Id, StringComparison.OrdinalIgnoreCase)))
                {
                    ReportStatus($"{rp.Id} ({rp.PackageId} : {rp.Version}) not installed.", Status.Error);
                    missingWorkloads.Add(rp);
                }
                else
                {
                    ReportStatus($"{rp.Id} ({rp.PackageId} : {rp.Version}) installed.", Status.Ok);

                    var workloadPacks = workloadManager.GetPacksInWorkload(rp.Id);

                    if (workloadPacks != null && workloadPacks.Any())
                    {
                        foreach (var wp in workloadPacks)
                        {
                            if (!(rp.IgnoredPackIds?.Any(ip => ip.Equals(wp.Id, StringComparison.OrdinalIgnoreCase)) ?? false))
                            {
                                requiredPacks.Add(wp);
                            }
                        }
                    }
                }
            }

            if (requiredPacks.Any())
            {
                history.ContributeState(this, "required_packs", requiredPacks.ToArray());
            }

            if (!missingWorkloads.Any())
            {
                return(Task.FromResult(DiagnosticResult.Ok(this)));
            }

            var remedies = missingWorkloads
                           .Select(mw => new DotNetWorkloadInstallSolution(SdkRoot, sdkVersion, mw, NuGetPackageSources));

            return(Task.FromResult(new DiagnosticResult(
                                       Status.Error,
                                       this,
                                       new Suggestion("Install Missing SDK Workloads",
                                                      remedies.ToArray()))));
        }