public override async Task <DiagnosticResult> Examine(SharedState history) { var vsinfo = await GetWindowsInfo(); var sentinelFiles = new List <string>(); foreach (var vi in vsinfo) { if (vi.Version.IsCompatible(MinimumVersion, ExactVersion)) { ReportStatus($"{vi.Version} - {vi.Path}", Status.Ok); var sentinel = Path.Combine(vi.Path, "MSBuild\\Current\\Bin\\SdkResolvers\\Microsoft.DotNet.MSBuildSdkResolver\\EnableWorkloadResolver.sentinel"); sentinelFiles.Add(sentinel); } else { ReportStatus($"{vi.Version}", null); } } if (sentinelFiles.Any()) { history.ContributeState(this, "sentinel_files", sentinelFiles.ToArray()); } if (vsinfo.Any(vs => vs.Version.IsCompatible(MinimumVersion, ExactVersion))) { return(DiagnosticResult.Ok(this)); } return(new DiagnosticResult(Status.Error, this)); }
public override async Task <DiagnosticResult> Examine(SharedState history) { var vsinfo = await GetMacInfo(); var ok = false; foreach (var vs in vsinfo) { if (vs.Version.IsCompatible(MinimumVersion, ExactVersion)) { ok = true; ReportStatus($"Visual Studio for Mac ({vs.Version})", Status.Ok); } else { ReportStatus($"Visual Studio for Mac ({vs.Version})", null); } } // Check VSCode sentinel files, ie: // ~/.vscode/extensions/ms-dotnettools.csharp-1.23.9/.omnisharp/1.37.8-beta.15/omnisharp/.msbuild/Current/Bin var vscodeExtPath = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), ".vscode", "extensions"); var sentinelFiles = new List <string>(); var vscodeExtDir = new DirectoryInfo(vscodeExtPath); if (vscodeExtDir.Exists) { var sdkResolverDirs = Directory.EnumerateDirectories(vscodeExtPath, "*Microsoft.DotNet.MSBuildSdkResolver", SearchOption.AllDirectories); if (sdkResolverDirs?.Any() ?? false) { foreach (var r in sdkResolverDirs) { if (!Directory.Exists(r)) { continue; } var sentinelFile = Path.Combine(r, "EnableWorkloadResolver.sentinel"); sentinelFiles.Add(sentinelFile); } } } if (sentinelFiles.Any()) { history.ContributeState(this, "sentinel_files", sentinelFiles.ToArray()); } if (ok || Optional) { return(DiagnosticResult.Ok(this)); } return(new DiagnosticResult(Status.Error, this)); }
public override async Task <DiagnosticResult> Examine(SharedState history) { var dn = new DotNetSdk(history); var missingDiagnosis = new DiagnosticResult(Status.Error, this, new Suggestion(".NET SDK not installed")); if (!dn.Exists) { return(missingDiagnosis); } var sdks = await dn.GetSdks(); var missingSdks = new List <Manifest.DotNetSdk>(); var sentinelFiles = new List <string>(); if (RequiredSdks?.Any() ?? false) { foreach (var rs in RequiredSdks) { var rsVersion = NuGetVersion.Parse(rs.Version); if (!sdks.Any(s => (rs.RequireExact && s.Version == rsVersion) || (!rs.RequireExact && s.Version >= rsVersion))) { missingSdks.Add(rs); } } } DotNetSdkInfo bestSdk = null; foreach (var sdk in sdks) { // See if the sdk is one of the required sdk's var requiredSdk = RequiredSdks.FirstOrDefault(rs => sdk.Version == NuGetVersion.Parse(rs.Version)); if (requiredSdk != null) { if (bestSdk == null || sdk.Version > bestSdk.Version) { bestSdk = sdk; } if (requiredSdk.EnableWorkloadResolver) { var sentinelPath = Path.Combine(sdk.Directory.FullName, "EnableWorkloadResolver.sentinel"); sentinelFiles.Add(sentinelPath); } ReportStatus($"{sdk.Version} - {sdk.Directory}", Status.Ok); } else { ReportStatus($"{sdk.Version} - {sdk.Directory}", null); } } // If we didn't get the exact one before, let's find a new enough one if (bestSdk == null) { bestSdk = sdks.OrderByDescending(s => s.Version)?.FirstOrDefault(); } // Find newest compatible sdk if (bestSdk != null) { history.SetEnvironmentVariable("DOTNET_SDK", bestSdk.Directory.FullName); history.SetEnvironmentVariable("DOTNET_SDK_VERSION", bestSdk.Version.ToString()); } // Add sentinel files that should be considered if (sentinelFiles.Any()) { history.ContributeState(this, "sentinel_files", sentinelFiles.ToArray()); } if (missingSdks.Any()) { var str = SdkListToString(); var remedies = new List <Solution>(); if (Util.CI) { remedies.AddRange(missingSdks .Select(ms => new DotNetSdkScriptInstallSolution(ms.Version))); } else { remedies.AddRange(missingSdks .Where(ms => !ms.Url.AbsolutePath.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) .Select(ms => new BootsSolution(ms.Url, ".NET SDK " + ms.Version) as Solution)); remedies.AddRange(missingSdks .Where(ms => ms.Url.AbsolutePath.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) .Select(ms => new MsInstallerSolution(ms.Url, ".NET SDK " + ms.Version))); } return(new DiagnosticResult(Status.Error, this, $".NET SDK {str} not installed.", new Suggestion($"Download .NET SDK {str}", remedies.ToArray()))); } return(new DiagnosticResult(Status.Ok, this)); }
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())))); }