diff options
author | Michael Hutchinson <m.j.hutchinson@gmail.com> | 2011-07-28 22:43:35 +0400 |
---|---|---|
committer | Michael Hutchinson <m.j.hutchinson@gmail.com> | 2011-07-28 22:46:00 +0400 |
commit | b3469caa337b5eba90e629f0de56baab4ec5bf3e (patch) | |
tree | 7bdaa17559d22d7e90dd66696d8dcfa23ce4d47f /main | |
parent | 5e603179aa96a00d329056208dc99202d443181e (diff) |
[Ide] Restore TryFixingFramework, rewritten
Diffstat (limited to 'main')
7 files changed, 61 insertions, 5 deletions
diff --git a/main/src/addins/MonoDeveloperExtensions/MonoMakefileFormat.cs b/main/src/addins/MonoDeveloperExtensions/MonoMakefileFormat.cs index 5f9582208d..ce6dd41f4a 100644 --- a/main/src/addins/MonoDeveloperExtensions/MonoMakefileFormat.cs +++ b/main/src/addins/MonoDeveloperExtensions/MonoMakefileFormat.cs @@ -195,5 +195,10 @@ namespace MonoDeveloper { yield break; } + + public bool SupportsFramework (MonoDevelop.Core.Assemblies.TargetFramework framework) + { + return true; + } } } diff --git a/main/src/addins/NUnit/Project/NUnitAssemblyGroupFileFormat.cs b/main/src/addins/NUnit/Project/NUnitAssemblyGroupFileFormat.cs index 5a2f34f688..702ae8c0c8 100644 --- a/main/src/addins/NUnit/Project/NUnitAssemblyGroupFileFormat.cs +++ b/main/src/addins/NUnit/Project/NUnitAssemblyGroupFileFormat.cs @@ -116,6 +116,11 @@ namespace MonoDevelop.NUnit { yield break; } + + public bool SupportsFramework (MonoDevelop.Core.Assemblies.TargetFramework framework) + { + return true; + } } } diff --git a/main/src/addins/prj2make-sharp-lib/VS2003ProjectFileFormat.cs b/main/src/addins/prj2make-sharp-lib/VS2003ProjectFileFormat.cs index 08c6f88638..6c3fab9e8b 100644 --- a/main/src/addins/prj2make-sharp-lib/VS2003ProjectFileFormat.cs +++ b/main/src/addins/prj2make-sharp-lib/VS2003ProjectFileFormat.cs @@ -238,6 +238,11 @@ namespace MonoDevelop.Prj2Make { yield break; } + + public bool SupportsFramework (MonoDevelop.Core.Assemblies.TargetFramework framework) + { + return framework.Id == MonoDevelop.Core.Assemblies.TargetFrameworkMoniker.NET_1_1; + } } enum TargetConvert diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/IFileFormat.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/IFileFormat.cs index 11a26b1e50..6c02e7d1f2 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/IFileFormat.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/IFileFormat.cs @@ -64,5 +64,7 @@ namespace MonoDevelop.Projects.Extensions // Returns a list of warnings to show to the user about compatibility issues // that may arise when exporting the object to this format. IEnumerable<string> GetCompatibilityWarnings (object obj); + + bool SupportsFramework (MonoDevelop.Core.Assemblies.TargetFramework framework); } -} +}
\ No newline at end of file diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MD1/MD1FileFormat.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MD1/MD1FileFormat.cs index 7f76607f71..07062a1afd 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MD1/MD1FileFormat.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Formats.MD1/MD1FileFormat.cs @@ -371,5 +371,10 @@ namespace MonoDevelop.Projects.Formats.MD1 { yield break; } + + public bool SupportsFramework (MonoDevelop.Core.Assemblies.TargetFramework framework) + { + return true; + } } -} +}
\ No newline at end of file diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/FileFormat.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/FileFormat.cs index 025729bc19..99c5af4ffe 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/FileFormat.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects/FileFormat.cs @@ -77,6 +77,11 @@ namespace MonoDevelop.Projects get { return format.SupportsMixedFormats; } } + public bool SupportsFramework (MonoDevelop.Core.Assemblies.TargetFramework framework) + { + return format.SupportsFramework (framework); + } + internal IFileFormat Format { get { return format; } } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectDescriptor.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectDescriptor.cs index 826f8c7f4f..3f15bd1508 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectDescriptor.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectDescriptor.cs @@ -33,6 +33,7 @@ using MonoDevelop.Projects; using System.IO; using System.Collections.Generic; using System.Xml; +using System.Linq; namespace MonoDevelop.Ide.Templates @@ -128,9 +129,13 @@ namespace MonoDevelop.Ide.Templates project.FileName = Path.Combine (projectCreateInformation.ProjectBasePath, pname); project.Name = pname; - if (project is DotNetProject) { + var dnp = project as DotNetProject; + if (dnp != null) { + if (policyParent.ParentSolution != null && !policyParent.ParentSolution.FileFormat.SupportsFramework (dnp.TargetFramework)) { + SetClosestSupportedTargetFramework (policyParent.ParentSolution.FileFormat, dnp); + } foreach (ProjectReference projectReference in references) - ((DotNetProject)project).References.Add (projectReference); + dnp.References.Add (projectReference); } foreach (SingleFileDescriptionTemplate resourceTemplate in resources) { @@ -144,7 +149,6 @@ namespace MonoDevelop.Ide.Templates } } - foreach (FileDescriptionTemplate fileTemplate in files) { try { fileTemplate.AddToProject (policyParent, project, defaultLanguage, project.BaseDirectory, null); @@ -154,5 +158,30 @@ namespace MonoDevelop.Ide.Templates } } } + + static void SetClosestSupportedTargetFramework (FileFormat format, DotNetProject project) + { + // If the solution format can't write this project due to an unsupported framework, try finding the + // closest valid framework. DOn't worry about whether it's installed, that's up to the user to correct. + TargetFramework curFx = project.TargetFramework; + var candidates = Runtime.SystemAssemblyService.GetTargetFrameworks () + .Where (fx => + //only frameworks with the same ID, else version comparisons are meaningless + fx.Id.Identifier == curFx.Id.Identifier && + //don't consider profiles, only full frameworks + fx.Id.Profile == null && + //and the project and format must support the framework + project.SupportsFramework (fx) && format.SupportsFramework (fx)) + //FIXME: string comparisons aren't a valid way to compare profiles, but it works w/released .NET versions + .OrderBy (fx => fx.Id.Version) + .ToList (); + + TargetFramework newFx = + candidates.FirstOrDefault (fx => string.CompareOrdinal (fx.Id.Version, curFx.Id.Version) > 0) + ?? candidates.LastOrDefault (); + + if (newFx != null) + project.TargetFramework = newFx; + } } }
\ No newline at end of file |