/// <summary> /// Supports simple wildcards. 1.* => 1.0, 1.2, up to but not including 2.0. /// Wildcards such as 1.*.3 are not supported. /// </summary> static bool SdkVersionSupported(NodeElement conditionNode, params DotNetCoreVersion[] versions) { string requiredSdkversion = conditionNode.GetAttribute("sdkVersion"); if (string.IsNullOrEmpty(requiredSdkversion)) { return(true); } // Special case '2.1' and '2.0'. if (requiredSdkversion == "2.1") { return(versions.Any(IsNetCoreSdk21) || MonoRuntimeInfoExtensions.CurrentRuntimeVersion.SupportsNetCore(requiredSdkversion)); } if (requiredSdkversion == "2.0") { return(versions.Any(IsNetCoreSdk20) || MonoRuntimeInfoExtensions.CurrentRuntimeVersion.SupportsNetCore(requiredSdkversion)); } requiredSdkversion = requiredSdkversion.Replace("*", string.Empty); DotNetCoreVersion requiredDotNetCoreVersion; DotNetCoreVersion.TryParse(requiredSdkversion, out requiredDotNetCoreVersion); if (requiredDotNetCoreVersion == null) { return(versions.Any(version => version.ToString().StartsWith(requiredSdkversion, StringComparison.OrdinalIgnoreCase))); } return(versions.Any(version => version.Major == requiredDotNetCoreVersion.Major && version.Minor == requiredDotNetCoreVersion.Minor)); }
public void FindMSBuildSDKsPath(string dotNetCorePath) { if (string.IsNullOrEmpty(dotNetCorePath)) { return; } string rootDirectory = Path.GetDirectoryName(dotNetCorePath); sdkRootPath = Path.Combine(rootDirectory, "sdk"); if (!Directory.Exists(sdkRootPath)) { return; } SdkVersions = GetInstalledSdkVersions(sdkRootPath) .OrderByDescending(version => version) .ToArray(); if (!SdkVersions.Any()) { return; } DotNetCoreVersion latestVersion = SdkVersions.FirstOrDefault(); SdksParentDirectory = Path.Combine(sdkRootPath, latestVersion.OriginalString); if (SdksParentDirectory == null) { return; } msbuildSDKsPath = Path.Combine(SdksParentDirectory, "Sdks"); Exist = true; }
DotNetCoreNotInstalledInfoBar CreateInfoBarInstance(bool unsupportedSdkVersion = false) { return(new DotNetCoreNotInstalledInfoBar { IsUnsupportedVersion = unsupportedSdkVersion, RequiredDotNetCoreVersion = DotNetCoreVersion.Parse(Project.TargetFramework.Id.Version), CurrentDotNetCorePath = sdkPaths.MSBuildSDKsPath, IsNetStandard = Project.TargetFramework.Id.IsNetStandard() }); }
public static bool IsLowerThanNetStandard16(this TargetFramework framework) { if (DotNetCoreVersion.TryParse(framework.Id.Version, out DotNetCoreVersion version)) { return(version.Major == 1 && version.Minor < 6); } return(false); }
public static bool IsNetStandardOrHigher(this TargetFrameworkMoniker framework, DotNetCoreVersion version) { DotNetCoreVersion.TryParse(framework.Version, out var dotNetCoreVersion); if (dotNetCoreVersion == null) { return(false); } return(framework.IsNetStandard() && dotNetCoreVersion >= version); }
public static string GetDotNetCoreDownloadUrl(DotNetCoreVersion version) { //special case for 2.0, 3.0, .. if (version.Minor == 0) { return(string.Format(BaseDotNetCoreDownloadUrl, version.Major)); } return(string.Format(BaseDotNetCoreDownloadUrl, $"{version.Major}{version.Minor}")); }
string GetSdksParentDirectory(DotNetCoreVersion targetVersion) { SdksParentDirectory = Path.Combine(SdkRootPath, targetVersion.OriginalString); if (SdksParentDirectory == null) { return(string.Empty); } return(Path.Combine(SdksParentDirectory, "Sdks")); }
public static bool IsNetCoreAppOrHigher(this TargetFramework framework, DotNetCoreVersion version) { DotNetCoreVersion.TryParse(framework.Id.Version, out var dotNetCoreVersion); if (dotNetCoreVersion == null) { return(false); } return(framework.Id.IsNetCoreApp() && dotNetCoreVersion >= version); }
Task ShowDotNetCoreNotInstalledDialog(string message, DotNetCoreVersion requiredVersion) { return(Runtime.RunInMainThread(() => { if (ShownDotNetCoreSdkNotInstalledDialogForSolution()) { return; } Project.ParentSolution.ExtendedProperties [ShownDotNetCoreSdkInstalledExtendedPropertyName] = "true"; CreateInfoBarInstance().Prompt(message, requiredVersion); })); }
public void Prompt(string message, DotNetCoreVersion requiredDotNetCoreVersion) { var items = new InfoBarItem [] { new InfoBarItem(GettextCatalog.GetString("Download .NET Core"), InfoBarItemKind.Button, DownloadButtonClicked, true) }; downloadUrl = requiredDotNetCoreVersion != null?DotNetCoreDownloadUrl.GetDotNetCoreDownloadUrl(requiredDotNetCoreVersion) : DotNetCoreDownloadUrl.GetDotNetCoreDownloadUrl(); IdeApp.Workbench.ShowInfoBar(false, new InfoBarOptions(message) { Items = items }); }
IEnumerable <DotNetCoreVersion> GetInstalledSdkVersions(string sdkRootPath) { return(Directory.EnumerateDirectories(sdkRootPath) .Select(directory => { if (!directory.Contains("NuGetFallbackFolder")) { return DotNetCoreVersion.GetDotNetCoreVersionFromDirectory(directory); } return null; }) .Where(version => version != null)); }
public static string GetDotNetCoreDownloadUrl(string version = "") { if (string.IsNullOrEmpty(version)) { return(string.Format(BaseDotNetCoreDownloadUrl, string.Empty)); } if (DotNetCoreVersion.TryParse(version, out var dotNetCoreVersion)) { return(GetDotNetCoreDownloadUrl(dotNetCoreVersion)); } return("https://dotnet.microsoft.com/download"); }
public static IEnumerable <DotNetCoreVersion> GetInstalledVersions(DotNetCorePath dotNetCorePath) { if (dotNetCorePath.IsMissing) { return(Enumerable.Empty <DotNetCoreVersion> ()); } string runtimePath = GetDotNetCoreRuntimePath(dotNetCorePath); if (!Directory.Exists(runtimePath)) { return(Enumerable.Empty <DotNetCoreVersion> ()); } return(Directory.EnumerateDirectories(runtimePath) .Select(directory => DotNetCoreVersion.GetDotNetCoreVersionFromDirectory(directory)) .Where(version => version != null)); }
Task ShowDotNetCoreNotInstalledDialog(bool unsupportedSdkVersion) { return(Runtime.RunInMainThread(() => { if (ShownDotNetCoreSdkNotInstalledDialogForSolution()) { return; } Project.ParentSolution.ExtendedProperties [ShownDotNetCoreSdkInstalledExtendedPropertyName] = "true"; using (var dialog = new DotNetCoreNotInstalledDialog()) { dialog.IsUnsupportedVersion = unsupportedSdkVersion; dialog.RequiredDotNetCoreVersion = DotNetCoreVersion.Parse(Project.TargetFramework.Id.Version); dialog.IsNetStandard = Project.TargetFramework.Id.IsNetStandard(); dialog.Show(); } })); }
public static IEnumerable <DotNetCoreVersion> GetInstalledVersions(string dotNetCorePath) { if (string.IsNullOrEmpty(dotNetCorePath)) { return(Enumerable.Empty <DotNetCoreVersion> ()); } string runtimePath = GetDotNetCoreRuntimePath(dotNetCorePath); if (!Directory.Exists(runtimePath)) { return(Enumerable.Empty <DotNetCoreVersion> ()); } return(Directory.EnumerateDirectories(runtimePath) .Select(directory => DotNetCoreVersion.GetDotNetCoreVersionFromDirectory(directory)) .Where(version => version != null) .OrderByDescending(version => version)); }
/// <summary> /// Slightly modified version of GenerateVersionId in UpdateInfo.cs /// to use 6 significant digits for revision. /// </summary> internal static long GenerateVersionId(DotNetCoreVersion version) { // For stable releases (that have no revision number), // we need a version Id that is higher then the previews // (which do have a revision number) to enable the comparison // to work on the feed. var revision = "999999"; if (version.IsPrerelease) { revision = FixVersionNumber(version.Revision).ToString("000000"); } var s = FixVersionNumber(version.Major) + FixVersionNumber(version.Minor).ToString("00") + FixVersionNumber(version.Patch).ToString("00") + revision; return(long.Parse(s)); }
protected override Task OnExecute( ProgressMonitor monitor, ExecutionContext context, ConfigurationSelector configuration, TargetFrameworkMoniker framework, SolutionItemRunConfiguration runConfiguration) { var requiredVersion = DotNetCoreVersion.Parse(Project.TargetFramework.Id.Version); if (DotNetCoreRuntime.IsMissing) { return(ShowCannotExecuteDotNetCoreApplicationDialog(DotNetCoreRuntime.GetNotInstalledVersionMessage(requiredVersion.OriginalString), requiredVersion)); } if (Project.TargetFramework.IsNetCoreApp() && !DotNetCoreRuntime.Versions.Any(x => x.OriginalString.StartsWith(Project.TargetFramework.Id.Version, StringComparison.OrdinalIgnoreCase))) { return(ShowCannotExecuteDotNetCoreApplicationDialog(DotNetCoreRuntime.GetNotInstalledVersionMessage(requiredVersion.OriginalString), requiredVersion)); } return(base.OnExecute(monitor, context, configuration, framework, runConfiguration)); }
/// <summary> /// Supports simple wildcards. 1.* => 1.0, 1.2, up to but not including 2.0. /// Wildcards such as 1.*.3 are not supported. /// </summary> static bool RuntimeVersionSupported(NodeElement conditionNode, params DotNetCoreVersion [] versions) { string requiredRuntimeVersion = conditionNode.GetAttribute("runtimeVersion"); if (string.IsNullOrEmpty(requiredRuntimeVersion)) { return(false); } requiredRuntimeVersion = requiredRuntimeVersion.Replace("*", string.Empty); DotNetCoreVersion requiredDotNetCoreVersion; DotNetCoreVersion.TryParse(requiredRuntimeVersion, out requiredDotNetCoreVersion); if (requiredDotNetCoreVersion == null) { return(versions.Any(version => version.ToString().StartsWith(requiredRuntimeVersion, StringComparison.OrdinalIgnoreCase))); } return(versions.Any(version => version.Major == requiredDotNetCoreVersion.Major && version.Minor == requiredDotNetCoreVersion.Minor)); }
/// <summary> /// .NET Core SDK version needs to be the mininum required SDK /// </summary> bool CheckIsSupportedSdkVersion(string sdkDirectory) { try { string sdkVersion = Path.GetFileName(sdkDirectory); if (DotNetCoreVersion.TryParse(sdkVersion, out var version)) { if (!DotNetCoreVersion.IsSdkSupported(version)) { LoggingService.LogInfo("Unsupported .NET Core SDK version installed '{0}'. '{1}'", sdkVersion, sdkDirectory); return(false); } } else { LoggingService.LogWarning("Unable to get version information for .NET Core SDK. '{0}'", sdkDirectory); } } catch (Exception ex) { LoggingService.LogError("Error checking sdk version.", ex); } return(true); }
static bool IsVersionOrHigher(this TargetFrameworkMoniker framework, DotNetCoreVersion version) { DotNetCoreVersion.TryParse(framework.Version, out var dotNetCoreVersion); if (dotNetCoreVersion == null) { return(false); } // Only compare $major.$minor, as Version parsing sets some fields to -1 // (Build), which gives false positives/negatives when comparing, for instance, // 3.1.100-preview1-014459 with an unsupported 3.1, and we're really only // interested in the target framework version, which only uses $major.$minor. if (dotNetCoreVersion.Major > version.Major) { return(true); } if (dotNetCoreVersion.Major < version.Major) { return(false); } return(dotNetCoreVersion.Minor >= version.Minor); }
public void FindMSBuildSDKsPath() { var dotNetCorePath = new DotNetCorePath(); if (dotNetCorePath.IsMissing) { return; } string rootDirectory = Path.GetDirectoryName(dotNetCorePath.FileName); string sdkRootPath = Path.Combine(rootDirectory, "sdk"); if (!Directory.Exists(sdkRootPath)) { return; } SdkVersions = GetInstalledSdkVersions(sdkRootPath) .OrderByDescending(version => version) .ToArray(); if (!SdkVersions.Any()) { return; } DotNetCoreVersion latestVersion = SdkVersions.FirstOrDefault(); SdksParentDirectory = Path.Combine(sdkRootPath, latestVersion.OriginalString); if (SdksParentDirectory == null) { return; } msbuildSDKsPath = Path.Combine(SdksParentDirectory, "Sdks"); MSBuildProjectService.RegisterProjectImportSearchPath("MSBuildSDKsPath", MSBuildSDKsPath); }
protected override void OnItemReady() { base.OnItemReady(); FileService.FileChanged += FileService_FileChanged; if (!IdeApp.IsInitialized) { return; } if (HasSdk && !IsDotNetCoreSdkInstalled()) { var requiredVersion = DotNetCoreVersion.Parse(Project.TargetFramework.Id.Version); ShowDotNetCoreNotInstalledDialog(DotNetCoreSdk.GetNotSupportedVersionMessage(requiredVersion.OriginalString), requiredVersion); } if (Project.ParentSolution == null) { return; } if (Project.ParentSolution.ExtendedProperties.Contains(GlobalJsonPathExtendedPropertyName)) { return; } //detect globaljson var globalJsonPath = sdkPaths.LookUpGlobalJson(Project.ParentSolution.BaseDirectory); if (globalJsonPath == null) { return; } Project.ParentSolution.ExtendedProperties [GlobalJsonPathExtendedPropertyName] = globalJsonPath; DetectSDK(); }
/// <summary> /// Project framework version is considered supported if the major version of the /// .NET Core SDK is greater or equal to the major version of the project framework. /// The fact that a .NET Core SDK is a preview version is ignored in this check. /// /// .NET Core SDK 1.0.4 supports .NET Core 1.0 and 1.1 /// .NET Core SDK 1.0.4 supports .NET Standard 1.0 to 1.6 /// .NET Core SDK 2.0 supports 1.0, 1.1 and 2.0 /// .NET Core SDK 2.0 supports .NET Standard 1.0 to 1.6 and 2.0 /// .NET Core SDK 2.1 supports 1.0, 1.1 and 2.0 /// .NET Core SDK 2.1 supports .NET Standard 1.0 to 1.6 and 2.0 /// </summary> static bool IsSupported(Version projectFrameworkVersion, DotNetCoreVersion sdkVersion) { return(sdkVersion.Major >= projectFrameworkVersion.Major); }
/// <summary> /// .NET Core 2.1.300 SDK is the lowest version that supports .NET Core App 2.1 /// </summary> static bool SupportsNetCore21(DotNetCoreVersion version) { return(version.Major >= 2 && version.Minor >= 1 && version.Patch >= 300); }
/// <summary> /// Project framework version is considered supported if the major version of the /// .NET Core SDK is greater or equal to the major version of the project framework. /// The fact that a .NET Core SDK is a preview version is ignored in this check. /// /// .NET Core SDK 1.0.4 supports .NET Core 1.0 and 1.1 /// .NET Core SDK 1.0.4 supports .NET Standard 1.0 to 1.6 /// .NET Core SDK 2.0 supports .NET Core 1.0, 1.1 and 2.0 /// .NET Core SDK 2.0 supports .NET Standard 1.0 to 1.6 and 2.0 /// .NET Core SDK 2.1.x (x < 300) supports .NET Core 1.0, 1.1 and 2.0 /// .NET Core SDK 2.1.x (x < 300) supports .NET Standard 1.0 to 1.6 and 2.0 /// .NET Core 2.1.300 supports .NET Core 1.0, 1.1, 2.0 and 2.1 /// .NET Core 2.1.300 supports .NET Standard 1.0 to 1.6, and 2.0, 2.1 /// </summary> static bool IsSupported(TargetFrameworkMoniker projectFramework, Version projectFrameworkVersion, DotNetCoreVersion sdkVersion) { // Special case .NET Core 2.1. if (IsNetCore21(projectFramework, projectFrameworkVersion) && !SupportsNetCore21(sdkVersion)) { return(false); } return(sdkVersion.Major >= projectFrameworkVersion.Major); }
Task ShowCannotExecuteDotNetCoreApplicationDialog(string message, DotNetCoreVersion requiredVersion) { return(Runtime.RunInMainThread(() => CreateInfoBarInstance().Prompt(message, requiredVersion))); }
//https://docs.microsoft.com/en-us/dotnet/core/tools/global-json public void ResolveSDK(string workingDir = "", bool forceLookUpGlobalJson = false) { if (!SdkVersions.Any()) { return; } DotNetCoreVersion targetVersion = null; if (forceLookUpGlobalJson) { GlobalJsonPath = LookUpGlobalJson(workingDir); } var specificVersion = ReadGlobalJson(); //if !global.json, returns latest if (string.IsNullOrEmpty(specificVersion)) { msbuildSDKsPath = GetSdksParentDirectory(GetLatestSdk()); Exist = true; return; } DotNetCoreVersion requiredVersion; DotNetCoreVersion.TryParse(specificVersion, out requiredVersion); if (requiredVersion == null) { msbuildSDKsPath = string.Empty; IsUnsupportedSdkVersion = true; Exist = false; return; } //if global.json exists and matches returns it targetVersion = SdkVersions.FirstOrDefault(x => x.OriginalString.IndexOf(specificVersion, StringComparison.InvariantCulture) == 0); if (targetVersion == null) { //if global.json exists and !matches then: if (requiredVersion >= DotNetCoreVersion.Parse("2.1")) { targetVersion = SdkVersions.Where(version => version.Major == requiredVersion.Major && version.Minor == requiredVersion.Minor) .OrderByDescending(version => version.Patch).FirstOrDefault(x => { return((x.Patch / 100 == requiredVersion.Patch / 100) && (x.Patch % 100 >= requiredVersion.Patch % 100)); }); } else { targetVersion = SdkVersions.Where(version => version.Major == requiredVersion.Major && version.Minor == requiredVersion.Minor) .OrderByDescending(version => version.Patch).FirstOrDefault(); } if (targetVersion == null) { msbuildSDKsPath = string.Empty; IsUnsupportedSdkVersion = true; Exist = false; return; } } msbuildSDKsPath = GetSdksParentDirectory(targetVersion); Exist = true; IsUnsupportedSdkVersion = false; }
/// <summary> /// 2.1.300 is the lowest version that supports .NET Core 2.1 projects. /// </summary> static bool IsNetCoreSdk21(DotNetCoreVersion version) => version.Major == 2 && version.Minor == 1 && version.Patch >= 300;
/// <summary> /// 2.1.300 is the lowest version that supports .NET Core 2.1 projects. /// </summary> static bool IsNetCoreSdk20(DotNetCoreVersion version) { return(version.Major == 2 && version.Minor <= 1 && version.Patch < 300); }
/// <summary> /// 2.1.300 is the lowest version that supports .NET Core 2.1 projects. /// </summary> static bool IsNetCoreSdk20(DotNetCoreVersion version) => version.Major == 2 && version.Minor <= 1 && version.Patch < 300;