Exemplo n.º 1
0
        public static bool TryLoadFromFile(string path, out Project project)
        {
            if(string.IsNullOrEmpty(path))
            {
                project = null;
                return false;
            }

            XDocument doc;
            try
            {
                doc = XDocument.Load(path);
            }
            catch(DirectoryNotFoundException)
            {
                project = null;
                return false;
            }
            catch(FileNotFoundException)
            {
                project = null;
                return false;
            }

            var nameNode = doc.XPathSelectElement(@"/x:Project/x:PropertyGroup/x:AssemblyName", NamespaceManager);
            var projectInfoNode = doc.XPathSelectElement(ProjectInfoXPath, NamespaceManager);
            XAttribute projectTypeAttribute = null;
            if(projectInfoNode != null)
            {
                projectTypeAttribute = projectInfoNode.Attribute("Type");
            }
            if(nameNode == null)
            {
                project = null;
                return false;
            }
            if(projectInfoNode != null)
            {
                var skippedNode = projectInfoNode.Attribute("Skip");
                if(skippedNode != null && skippedNode.Value == "true")
                {
                    project = null;
                    return false;
                }

                var type = projectTypeAttribute != null ? ProjectTypeHelper.Parse(projectTypeAttribute.Value) : ProjectType.Unknown;
                project = type.CreateInstance(nameNode.Value, path);
            }
            else
            {
                project = new UnknownProject(nameNode.Value, path);
            }

            return project.TryLoad(doc);
        }
Exemplo n.º 2
0
 public static Project CreateEntryProject(Project mainProject, string outputPath, IEnumerable<Project> additionalProjects)
 {
     return new EntryProject(mainProject.StartupObject, outputPath, new [] { mainProject }.Union(additionalProjects));
 }