diff options
author | Rodrigo Moya <rodrigo.moya@xamarin.com> | 2020-01-08 21:38:05 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-08 21:38:05 +0300 |
commit | e49b85a8cffb88fbd0f87b50af22cc939c89cc1d (patch) | |
tree | d7dc7a9f332be6cb7b3abecc3ad59d0fc93ea295 | |
parent | 7ef36549540678edfe4e7e807cec15052fb5424a (diff) | |
parent | afbb9be764961846e3db3794609c17972ceb4905 (diff) |
Merge pull request #9400 from mono/pr-ignore-unsupported-sdks
[DotNetCore] Ignore unsupported SDKs in template wizard
6 files changed, 117 insertions, 7 deletions
diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizard.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizard.cs index cfe5ee2ad7..41e3ce3b1e 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizard.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizard.cs @@ -87,6 +87,8 @@ namespace MonoDevelop.DotNetCore.Templating } else { targetFrameworks = DotNetCoreProjectSupportedTargetFrameworks.GetNetCoreAppTargetFrameworksWithSdkSupport ().ToList (); + RemoveUnsupportedNetCoreAppTargetFrameworks (targetFrameworks); + if (!SupportsNetCore2x ()) { RemoveUnsupportedNetCoreApp2xTargetFrameworks (targetFrameworks); } @@ -105,6 +107,11 @@ namespace MonoDevelop.DotNetCore.Templating targetFrameworks.RemoveAll (framework => framework.IsLowerThanNetStandard16 ()); } + static void RemoveUnsupportedNetCoreAppTargetFrameworks (List<TargetFramework> targetFrameworks) + { + targetFrameworks.RemoveAll (framework => framework.IsNetCoreAppOrHigher (DotNetCoreSdk.DotNetCoreUnsupportedTargetFrameworkVersion)); + } + /// <summary> /// FSharp class library project template and the Razor Pages project template do not support /// targeting 1.x versions so remove these frameworks. diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests.csproj b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests.csproj index f1e8486702..e762a7fdd9 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests.csproj +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests.csproj @@ -43,6 +43,7 @@ <Compile Include="MonoDevelop.DotNetCore.Tests\PackProjectTests.cs" /> <Compile Include="MonoDevelop.DotNetCore.Tests\FrameworkReferenceTests.cs" /> <Compile Include="MonoDevelop.DotNetCore.Tests\GlobalToolTests.cs" /> + <Compile Include="MonoDevelop.DotNetCore.Tests\TargetFrameworkTests.cs" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\..\..\..\external\guiunit\src\framework\GuiUnit_NET_4_5.csproj"> diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests/DotNetCoreProjectTemplateWizardTests.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests/DotNetCoreProjectTemplateWizardTests.cs index 6dec6e10c7..323e7ef068 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests/DotNetCoreProjectTemplateWizardTests.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests/DotNetCoreProjectTemplateWizardTests.cs @@ -24,6 +24,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using System.Linq; using System.Reflection; using MonoDevelop.Core.StringParsing; using MonoDevelop.DotNetCore.Templating;
@@ -322,6 +323,20 @@ namespace MonoDevelop.DotNetCore.Tests } [Test] + public void NetCoreApp_UnsupportedSDKInstalled_TemplateDoesNotShowUnsupported () + { + CreateWizard (); + DotNetCoreRuntimesInstalled ("2.1.14", "2.2.8", "3.0.1", "3.1.0", $"{DotNetCoreSdk.DotNetCoreUnsupportedTargetFrameworkVersion.Major}.{DotNetCoreSdk.DotNetCoreUnsupportedTargetFrameworkVersion.Minor}.0"); + DotNetCoreSdksInstalled ("2.1.702", "2.2.402", "3.0.101", "3.1.100", $"{DotNetCoreSdk.DotNetCoreUnsupportedTargetFrameworkVersion.Major}.{DotNetCoreSdk.DotNetCoreUnsupportedTargetFrameworkVersion.Minor}.0"); + + int pages = wizard.TotalPages; + + Assert.AreEqual (1, pages); + Assert.AreEqual (4, wizard.TargetFrameworks.Count); + Assert.False (wizard.TargetFrameworks.Any (x => x.Id.IsNetCoreAppOrHigher (DotNetCoreSdk.DotNetCoreUnsupportedTargetFrameworkVersion))); + } + + [Test] public void NetCoreLibrary_NetCore20Installed () { CreateWizard (); diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests/TargetFrameworkTests.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests/TargetFrameworkTests.cs new file mode 100644 index 0000000000..25eec27758 --- /dev/null +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Tests/MonoDevelop.DotNetCore.Tests/TargetFrameworkTests.cs @@ -0,0 +1,76 @@ +// +// TargetFrameworkTests.cs +// +// Author: +// Rodrigo Moya <rodrigo.moya@xamarin.com> +// +// Copyright (c) 2019 Microsoft, Corp. (http://www.microsoft.com) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using MonoDevelop.Core; +using MonoDevelop.Core.Assemblies; +using NUnit.Framework; + +namespace MonoDevelop.DotNetCore.Tests +{ + [TestFixture] + class TargetFrameworkTests : DotNetCoreTestBase + { + [TestCase ("1.0", "1.0", "1.1", "2.0", "2.1", "2.2", "3.0", "3.1")] + [TestCase ("1.1", "1.1", "2.0", "2.1", "2.2", "3.0", "3.1")] + [TestCase ("2.0", "2.0", "2.1", "2.2", "3.0", "3.1")] + [TestCase ("2.1", "2.1", "2.2", "3.0", "3.1")] + [TestCase ("2.2", "2.2", "3.0", "3.1")] + [TestCase ("3.0", "3.0", "3.1")] + public void NetCoreApp_IsVersionOrHigher (string version, params string[] versionsToCheck) + { + var frameworkVersion = DotNetCoreVersion.Parse (version); + foreach (var v in versionsToCheck) { + var framework = CreateTargetFramework (".NETCoreApp", v); + Assert.True (framework.IsNetCoreAppOrHigher (frameworkVersion)); + } + } + + [TestCase ("1.0", "1.0", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "2.0", "2.1")] + [TestCase ("1.1", "1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "2.0", "2.1")] + [TestCase ("1.2", "1.2", "1.3", "1.4", "1.5", "1.6", "2.0", "2.1")] + [TestCase ("1.3", "1.3", "1.4", "1.5", "1.6", "2.0", "2.1")] + [TestCase ("1.4", "1.4", "1.5", "1.6", "2.0", "2.1")] + [TestCase ("1.5", "1.5", "1.6", "2.0", "2.1")] + [TestCase ("1.6", "1.6", "2.0", "2.1")] + [TestCase ("2.0", "2.0", "2.1")] + [TestCase ("2.1", "2.1")] + public void NetStandard_IsVersionOrHigher (string version, params string [] versionsToCheck) + { + var frameworkVersion = DotNetCoreVersion.Parse (version); + foreach (var v in versionsToCheck) { + var framework = CreateTargetFramework (".NETStandard", v); + Assert.True (framework.IsNetStandardOrHigher (frameworkVersion)); + } + } + + static TargetFramework CreateTargetFramework (string identifier, string version) + { + var moniker = new TargetFrameworkMoniker (identifier, version); + return Runtime.SystemAssemblyService.GetTargetFramework (moniker); + } + } +} diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreSdk.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreSdk.cs index 50992bf057..63dc50df57 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreSdk.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/DotNetCoreSdk.cs @@ -36,6 +36,7 @@ namespace MonoDevelop.DotNetCore public static class DotNetCoreSdk { static readonly Version DotNetCoreVersion2_1 = new Version (2, 1, 0); + internal static readonly DotNetCoreVersion DotNetCoreUnsupportedTargetFrameworkVersion = new DotNetCoreVersion (3, 2, 0); static DotNetCoreSdk () { diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/TargetFrameworkMonikerExtensions.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/TargetFrameworkMonikerExtensions.cs index 0e52b80399..71c92e557c 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/TargetFrameworkMonikerExtensions.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore/TargetFrameworkMonikerExtensions.cs @@ -50,22 +50,32 @@ namespace MonoDevelop.DotNetCore return framework.IsNetStandard () || framework.IsNetCoreApp (); } - public static bool IsNetCoreAppOrHigher (this TargetFrameworkMoniker framework, DotNetCoreVersion version) + static bool IsVersionOrHigher (this TargetFrameworkMoniker framework, DotNetCoreVersion version) { DotNetCoreVersion.TryParse (framework.Version, out var dotNetCoreVersion); if (dotNetCoreVersion == null) return false; - return framework.IsNetCoreApp () && dotNetCoreVersion >= version; + // 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 static bool IsNetStandardOrHigher (this TargetFrameworkMoniker framework, DotNetCoreVersion version) + public static bool IsNetCoreAppOrHigher (this TargetFrameworkMoniker framework, DotNetCoreVersion version) { - DotNetCoreVersion.TryParse (framework.Version, out var dotNetCoreVersion); - if (dotNetCoreVersion == null) - return false; + return framework.IsNetCoreApp () && framework.IsVersionOrHigher (version); + } - return framework.IsNetStandard () && dotNetCoreVersion >= version; + public static bool IsNetStandardOrHigher (this TargetFrameworkMoniker framework, DotNetCoreVersion version) + { + return framework.IsNetStandard () && framework.IsVersionOrHigher (version); } } } |