diff options
author | Rodrigo Moya <rodrigo.moya@xamarin.com> | 2019-09-23 19:01:22 +0300 |
---|---|---|
committer | Rodrigo Moya <rodrigo.moya@xamarin.com> | 2019-09-23 20:01:30 +0300 |
commit | 0ca4a0d7bdcf652ee0bd7a9e9b5c3cf1a3ee9bde (patch) | |
tree | dcf04f840e65d35fbdd7b53acdf2ebe327945b38 /main/src/addins/MonoDevelop.DotNetCore | |
parent | 2fc3609c3471ebe6613b25a8513330f9f387e959 (diff) |
[AspNetCore] Don't allow selecting 2.x target framework for 3.0-only templates
Fixes https://devdiv.visualstudio.com/DevDiv/_workitems/edit/980398
Diffstat (limited to 'main/src/addins/MonoDevelop.DotNetCore')
2 files changed, 57 insertions, 1 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 f89d775186..cfe5ee2ad7 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizard.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizard.cs @@ -34,6 +34,7 @@ namespace MonoDevelop.DotNetCore.Templating { class DotNetCoreProjectTemplateWizard : TemplateWizard { + const string defaultParameterNetCore30 = "UseNetCore30"; const string defaultParameterNetCore20 = "UseNetCore20"; const string defaultParameterNetCore1x = "UseNetCore1x"; @@ -86,6 +87,9 @@ namespace MonoDevelop.DotNetCore.Templating } else { targetFrameworks = DotNetCoreProjectSupportedTargetFrameworks.GetNetCoreAppTargetFrameworksWithSdkSupport ().ToList (); + if (!SupportsNetCore2x ()) { + RemoveUnsupportedNetCoreApp2xTargetFrameworks (targetFrameworks); + } if (!SupportsNetCore1x ()) { RemoveUnsupportedNetCoreApp1xTargetFrameworks (targetFrameworks); } @@ -111,6 +115,15 @@ namespace MonoDevelop.DotNetCore.Templating } /// <summary> + /// Some templates (Blazor, Worker) are only available on 3.0. + /// </summary> + /// <param name="targetFrameworks"></param> + static void RemoveUnsupportedNetCoreApp2xTargetFrameworks (List<TargetFramework> targetFrameworks) + { + targetFrameworks.RemoveAll (framework => !framework.IsNetCoreAppOrHigher (DotNetCoreVersion.Parse ("3.0"))); + } + + /// <summary> /// Set default parameter values if no wizard will be displayed. /// </summary> void ConfigureDefaultParameters () @@ -131,6 +144,15 @@ namespace MonoDevelop.DotNetCore.Templating } else { Parameters [defaultParameterNetCore20] = "true"; } + } else if (!SupportsNetCore2x ()) { + var highestFramework = DotNetCoreProjectSupportedTargetFrameworks.GetNetCoreAppTargetFrameworksWithSdkSupport ().FirstOrDefault (); + if (highestFramework != null && highestFramework.IsNetCoreAppOrHigher (DotNetCoreVersion.Parse ("3.0"))) { + var parameter = highestFramework.GetParameterName (); + if (!string.IsNullOrEmpty (parameter)) + Parameters [parameter] = "true"; + } else { + Parameters [defaultParameterNetCore30] = "true"; + } } else { var highestFramework = DotNetCoreProjectSupportedTargetFrameworks.GetNetCoreAppTargetFrameworksWithSdkSupport ().FirstOrDefault (); if (highestFramework != null) { @@ -162,11 +184,21 @@ namespace MonoDevelop.DotNetCore.Templating } } + bool SupportsNetCore2x () + { + bool supportsNetCore30Only = IsSupportedParameter ("AspNetCoreBlazor") || + IsSupportedParameter ("AspNetCoreWorker"); + + return !supportsNetCore30Only; + } + bool SupportsNetCore1x () { bool supportsNetCore20Only = IsSupportedParameter ("FSharpNetCoreLibrary") || IsSupportedParameter ("RazorPages") || - IsSupportedParameter ("FSharpWebApi"); + IsSupportedParameter ("FSharpWebApi") || + IsSupportedParameter ("AspNetCoreBlazor") || + IsSupportedParameter ("AspNetCoreWorker"); return !supportsNetCore20Only; } 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 b74da57284..6dec6e10c7 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 @@ -439,6 +439,30 @@ namespace MonoDevelop.DotNetCore.Tests Assert.AreEqual (1, wizard.TargetFrameworks.Count); } + [TestCase ("AspNetCoreBlazor", "2.1.802")] + [TestCase ("AspNetCoreBlazor", "2.2.403")] + [TestCase ("AspNetCoreWorker", "2.1.802")] + [TestCase ("AspNetCoreWorker", "2.2.403")] + public void NetCoreApp_NetCore30AndNetCore2xInstalled_TemplateDoesNotSupportNetCore2x (string supportedParameters, string sdk2x) + { + CreateWizard (); + AddSupportedParameters (supportedParameters); + DotNetCoreRuntimesInstalled ("3.0.100", sdk2x); + DotNetCoreSdksInstalled ("3.0.100", sdk2x); + + int pages = wizard.TotalPages; + + Assert.AreEqual (0, pages); + Assert.IsFalse (WizardHasParameter ("UseNetStandard20")); + Assert.IsFalse (WizardHasParameter ("UseNetStandard1x")); + Assert.IsTrue (wizard.Parameters.GetBoolValue ("UseNetCore30")); + Assert.IsFalse (WizardHasParameter ("UseNetCore20")); + Assert.IsFalse (WizardHasParameter ("UseNetCore1x")); + Assert.IsFalse (WizardHasParameter ("framework")); + Assert.AreEqual (".NETCoreApp,Version=v3.0", wizard.TargetFrameworks [0].Id.ToString ()); + Assert.AreEqual (1, wizard.TargetFrameworks.Count); + } + [Test] public void NetCoreApp_NetCore30Installed () { |