diff options
author | Rodrigo Moya <rodrigo.moya@xamarin.com> | 2019-10-26 00:24:23 +0300 |
---|---|---|
committer | Rodrigo Moya <rodrigo.moya@xamarin.com> | 2019-10-27 03:52:24 +0300 |
commit | cb0396727279994371624682a9f2a779cc39432e (patch) | |
tree | a2ca92f7a4e8d50ddd6c86e20ce88ce2ecff788f /main/src/addins/MonoDevelop.DotNetCore | |
parent | 2673f06e044397929fe7623f123fddff9900ae84 (diff) |
[DotNetCore] Allow re-targetting to any of the supported frameworks
Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/973338
Diffstat (limited to 'main/src/addins/MonoDevelop.DotNetCore')
2 files changed, 54 insertions, 18 deletions
diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Gui/DotNetCoreRuntimeOptionsPanelWidget.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Gui/DotNetCoreRuntimeOptionsPanelWidget.cs index 25915b90f6..11dcf4ce29 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Gui/DotNetCoreRuntimeOptionsPanelWidget.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Gui/DotNetCoreRuntimeOptionsPanelWidget.cs @@ -35,7 +35,7 @@ namespace MonoDevelop.DotNetCore.Gui { partial class DotNetCoreRuntimeOptionsPanelWidget { - readonly List<TargetFramework> frameworks; + readonly List<TargetFramework> installedFrameworks; readonly DotNetProject project; readonly DotNetCoreProjectExtension dotNetCoreProject; @@ -56,36 +56,38 @@ namespace MonoDevelop.DotNetCore.Gui } else { dotNetCoreProject = project.GetFlavor<DotNetCoreProjectExtension> (); var supportedTargetFrameworks = new DotNetCoreProjectSupportedTargetFrameworks (project); - frameworks = supportedTargetFrameworks.GetFrameworks ().ToList (); + installedFrameworks = supportedTargetFrameworks.GetFrameworks ().ToList (); + var knownFrameworks = supportedTargetFrameworks.GetKnownFrameworks () + .Concat (installedFrameworks) + .Distinct () + .ToList (); - bool notInstalled = false; - if (!frameworks.Any (fx => fx.Id == project.TargetFramework.Id)) { - frameworks.Add (project.TargetFramework); - notInstalled = true; + if (!knownFrameworks.Any (fx => fx.Id == project.TargetFramework.Id)) { + knownFrameworks.Add (project.TargetFramework); } //sort by id ascending, version descending - frameworks.Sort ((x, y) => { + knownFrameworks.Sort ((x, y) => { var cmp = string.CompareOrdinal (x.Id.Identifier, y.Id.Identifier); if (cmp != 0) return cmp; return string.CompareOrdinal (y.Id.Version, x.Id.Version); }); - for (int i = 0; i < frameworks.Count; i++) { - var fx = frameworks[i]; + for (int i = 0; i < knownFrameworks.Count; i++) { + var fx = knownFrameworks[i]; + if (installedFrameworks.Any (f => f.Id == fx.Id)) { + runtimeVersionCombo.AppendText (fx.GetDisplayName ()); + } else { + runtimeVersionCombo.AppendText (GettextCatalog.GetString ("{0} (Not installed)", fx.GetDisplayName ())); + } + if (project.TargetFramework.Id == fx.Id) { - if (notInstalled) - runtimeVersionCombo.AppendText (GettextCatalog.GetString ("{0} (Not installed)", fx.GetDisplayName ())); - else - runtimeVersionCombo.AppendText (fx.GetDisplayName ()); runtimeVersionCombo.Active = i; - } else { - runtimeVersionCombo.AppendText (fx.GetDisplayName ()); } } - Sensitive = frameworks.Count > 1; + Sensitive = knownFrameworks.Count > 1; } } @@ -94,10 +96,10 @@ namespace MonoDevelop.DotNetCore.Gui if (project == null || runtimeVersionCombo.Active == -1 || project.HasMultipleTargetFrameworks) return; - TargetFramework framework = frameworks [runtimeVersionCombo.Active]; + TargetFramework framework = installedFrameworks [runtimeVersionCombo.Active]; if (framework != project.TargetFramework) { - project.TargetFramework = frameworks [runtimeVersionCombo.Active]; + project.TargetFramework = installedFrameworks [runtimeVersionCombo.Active]; } } } diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectSupportedTargetFrameworks.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectSupportedTargetFrameworks.cs index 468cfd1aa8..261c1b103b 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectSupportedTargetFrameworks.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreProjectSupportedTargetFrameworks.cs @@ -60,6 +60,40 @@ namespace MonoDevelop.DotNetCore return new TargetFramework [0]; } + static string [] supportedNetStandardVersions = new string [] { + "2.1", "2.0", "1.6", "1.5", "1.4", "1.3", "1.2", "1.1" + }; + static string [] supportedNetCoreAppVersions = new string [] { + "3.1", "3.0", "2.2", "2.1" + }; + + public IEnumerable<TargetFramework> GetKnownFrameworks () + { + static IEnumerable<TargetFramework> GetKnownNetStandardFrameworks () + { + foreach (var v in supportedNetStandardVersions) { + yield return CreateTargetFramework (".NETStandard", v); + } + } + + static IEnumerable<TargetFramework> GetKnownNetCoreAppFrameworks () + { + foreach (var v in supportedNetCoreAppVersions) { + yield return CreateTargetFramework (".NETCoreApp", v); + } + } + + if (framework.IsNetStandard ()) { + return GetKnownNetStandardFrameworks (); + } else if (framework.IsNetCoreApp ()) { + return GetKnownNetCoreAppFrameworks (); + } else if (framework.IsNetFramework ()) { + return GetNetFrameworkTargetFrameworks (); + } + + return new TargetFramework [0]; + } + public static IEnumerable<TargetFramework> GetNetStandardTargetFrameworks () { if (DotNetCoreRuntime.IsNetCore30Installed () || MonoRuntimeInfoExtensions.CurrentRuntimeVersion.SupportsNetStandard21 ()) |