예제 #1
0
        public override async Task <SolutionItem> CreateSolutionItem(ProgressMonitor monitor, SolutionLoadContext ctx, string fileName)
        {
            MSBuildProject p       = null;
            Project        project = null;

            if (!string.IsNullOrEmpty(fileName))
            {
                p = await MSBuildProject.LoadAsync(fileName);

                if (ctx != null && ctx.Solution != null)
                {
                    p.EngineManager     = ctx.Solution.MSBuildEngineManager;
                    p.SolutionDirectory = ctx.Solution.ItemDirectory;
                }

                var migrators = MSBuildProjectService.GetMigrableFlavors(p.ProjectTypeGuids);
                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));
                }

                                #pragma warning disable 612
                p.UseMSBuildEngine = MSBuildSupport != MSBuildSupport.NotSupported &&
                                     MSBuildProjectService.GetMSBuildSupportForFlavors(p.ProjectTypeGuids);
                                #pragma warning restore 612

                // Evaluate the project now. If evaluation fails an exception will be thrown, and when that
                // happens the solution will create a placeholder project.
                p.Evaluate();
            }

            if (project == null)
            {
                project = await base.CreateSolutionItem(monitor, ctx, 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);
        }