diff options
author | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-15 21:25:21 +0300 |
---|---|---|
committer | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-15 22:01:36 +0300 |
commit | c01e9a973783cda83d6f6aa702842c6438050bc4 (patch) | |
tree | f0168bc741c06b980e61ef9dd7100756cae73bb4 /main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions | |
parent | 4d8e96a1003ead9b3ce76b1c71602795d031eedb (diff) |
Fix unsupported project loading
Properly load unsupported projects as UnknownProject, and support saving
simple changes such as adding/removing files.
Diffstat (limited to 'main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions')
-rw-r--r-- | main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/ProjectTypeNode.cs | 22 | ||||
-rw-r--r-- | main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/SolutionItemTypeNode.cs | 18 |
2 files changed, 16 insertions, 24 deletions
diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/ProjectTypeNode.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/ProjectTypeNode.cs index 186bbcd097..140f09a6b9 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/ProjectTypeNode.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/ProjectTypeNode.cs @@ -24,6 +24,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; +using System.Linq; using System.Threading.Tasks; using System.Collections.Generic; using MonoDevelop.Projects.Formats.MSBuild; @@ -46,6 +47,7 @@ namespace MonoDevelop.Projects.Extensions public override async Task<SolutionItem> CreateSolutionItem (ProgressMonitor monitor, string fileName) { MSBuildProject p = null; + Project project = null; if (!string.IsNullOrEmpty (fileName)) { p = await MSBuildProject.LoadAsync (fileName); @@ -53,24 +55,26 @@ namespace MonoDevelop.Projects.Extensions if (migrators.Count > 0) await MSBuildProjectService.MigrateFlavors (monitor, fileName, Guid, p, migrators); + var unsupporedFlavor = p.ProjectTypeGuids.FirstOrDefault (fid => !MSBuildProjectService.IsKnownFlavorGuid (fid) && !MSBuildProjectService.IsKnownTypeGuid (fid)); + if (unsupporedFlavor != null) { + // The project has a flavor that's not supported. Return a fake project (if possible). + return MSBuildProjectService.CreateUnknownSolutionItem (monitor, fileName, Guid, unsupporedFlavor, null); + } + if (MSBuildSupport == MSBuildSupport.NotSupported || MSBuildProjectService.GetMSBuildSupportForFlavors (p.ProjectTypeGuids) == MSBuildSupport.NotSupported) p.UseMSBuildEngine = false; // Evaluate the project now. If evaluation fails an exception will be thrown, and when that // happens the solution will create a placeholder project. - try { - p.Evaluate (); - } catch (ProjectEvaluationException ex) { - if (p.UseMSBuildEngine) { - p.UseMSBuildEngine = false; - p.Evaluate (); - } - } + p.Evaluate (); } - var project = await base.CreateSolutionItem (monitor, fileName) as Project; + if (project == null) + project = await base.CreateSolutionItem (monitor, fileName) as Project; + if (project == null) throw new InvalidOperationException ("Project node type is not a subclass of MonoDevelop.Projects.Project"); + if (p != null) project.SetCreationContext (Project.CreationContext.Create (p, Guid)); return project; diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/SolutionItemTypeNode.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/SolutionItemTypeNode.cs index b413e0bc69..7757b02041 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/SolutionItemTypeNode.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.Extensions/SolutionItemTypeNode.cs @@ -109,21 +109,9 @@ namespace MonoDevelop.Projects.Extensions if (factory == null) factory = (SolutionItemFactory)Activator.CreateInstance (ItemType); item = await factory.CreateItem (fileName, Guid); - } else { - try { - // Some subclasses (such as ProjectTypeNode) need to assign some data to - // the object before it is initialized. However, by default initialization - // is automatically made by the constructor, so to support this scenario - // the initialization has to be delayed. This is done by setting the - // MonoDevelop.DelayItemInitialization logical context property. - // When this property is set, the object is not initialized, and it has - // to be manually initialized by calling EnsureInitialized. - CallContext.LogicalSetData ("MonoDevelop.DelayItemInitialization", true); - item = (SolutionItem)Activator.CreateInstance (ItemType, true); - } finally { - CallContext.LogicalSetData ("MonoDevelop.DelayItemInitialization", false); - } - } + } else + item = MSBuildProjectService.CreateUninitializedInstance (ItemType); + item.TypeGuid = Guid; return item; } |