Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit 371fdde

Browse files
committed
[Core] Fix project options showing all frameworks for sdk project
If a SDK style project targeted net472 then Project Options - Build - General would list all target frameworks, not just the .NET Framework. The problem was that the SdkProjectExtension overrode the OnGetSupportsFramework and returns true so it can support any target framework. This prevents the RuntimeOptionsPanel from listing only the related target frameworks for the project. To fix this the SdkProjectExtension no longer indicates it supports all target frameworks and instead the DotNetProject checks if the project has a SdkProjectExtension enabled when setting the TargetFramework property. If there an associated SdkProjectExtension then an exception is not thrown when the target framework is not known. Fixes VSTS #992631 - net472 sdk style project allows any target framework to be selected in project options
1 parent 169c3b6 commit 371fdde

File tree

2 files changed

+3
-14
lines changed

2 files changed

+3
-14
lines changed

main/src/core/MonoDevelop.Core/MonoDevelop.Projects/DotNetProject.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,9 @@ public TargetFramework TargetFramework {
438438
return targetFramework;
439439
}
440440
set {
441-
if (!SupportsFramework (value))
441+
// Allow all SDK style projects to be loaded even if the framework is unknown.
442+
// A PackageReference may define the target framework with an imported MSBuild file (e.g. Tizen.NET projects).
443+
if (!SupportsFramework (value) && !HasFlavor<SdkProjectExtension> ())
442444
throw new ArgumentException ("Project does not support framework '" + value.Id.ToString () +"'");
443445
if (value == null)
444446
value = Runtime.SystemAssemblyService.GetTargetFramework (GetDefaultTargetFrameworkForFormat (ToolsVersion));

main/src/core/MonoDevelop.Core/MonoDevelop.Projects/SdkProjectExtension.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,19 +68,6 @@ internal protected override bool SupportsObject (WorkspaceObject item)
6868
return base.SupportsObject (item) && IsSdkProject ((DotNetProject)item);
6969
}
7070

71-
internal protected override bool OnGetSupportsFramework (TargetFramework framework)
72-
{
73-
// Allow all SDK style projects to be loaded even if the framework is unknown.
74-
// A PackageReference may define the target framework with an imported MSBuild file.
75-
return true;
76-
}
77-
78-
/// <summary>
79-
/// Currently this project extension is enabled for all SDK style projects and
80-
/// not just for .NET Core and .NET Standard projects. SDK project support
81-
/// should be separated out from this extension so it can be enabled only for
82-
/// .NET Core and .NET Standard projects.
83-
/// </summary>
8471
bool IsSdkProject (DotNetProject project)
8572
{
8673
return project.MSBuildProject.GetReferencedSDKs ().Length > 0;

0 commit comments

Comments
 (0)