public void Add(AssemblyProject assemblyProject)
 {
     //ToDo: Save if it has another version no.
     if (!assemblyProjectCollection.ContainsKey(assemblyProject.Id))
     {
         assemblyProjectCollection[assemblyProject.Id] = assemblyProject;
     }
 }
        /// <summary>
        /// Create a project from file
        /// </summary>
        /// <param name="projectPath">The project path.</param>
        /// <param name="solution">The parent solution.</param>
        /// <returns>a partially parsed project</returns>
        public Project FromFile(string projectPath)
        {
            ////Tracer.Debug("Pre-parsing {0} ...", projectPath);
            Project project = new Project();

            XmlDocument doc = new XmlDocument();

            doc.Load(projectPath);
            XmlNamespaceManager ns = new XmlNamespaceManager(doc.NameTable);

            ns.AddNamespace("msbuild", "http://schemas.microsoft.com/developer/msbuild/2003");

            var nameNode = doc.SelectSingleNode("/msbuild:Project/msbuild:PropertyGroup/msbuild:AssemblyName/text()", ns)
                           ?? doc.SelectSingleNode("/msbuild:Project/msbuild:PropertyGroup/msbuild:Name/text()", ns);

            project.Name         = nameNode.Value;
            project.AssemblyName = project.Name;
            project.ProjectType  = Guid.Empty; // TODO: fix project type guid somehow
            project.Guid         = new Guid(doc.SelectSingleNode("/msbuild:Project/msbuild:PropertyGroup/msbuild:ProjectGuid/text()", ns).Value);
            project.Path         = System.IO.Path.GetFullPath(projectPath);


            foreach (XmlAttribute att in doc.SelectNodes("/msbuild:Project/msbuild:ItemGroup/msbuild:Reference/@Include", ns))
            {
                //ToDo: Also get the version number
                string[] attributes     = att.Value.Split(',');
                string   name           = attributes[0];
                string   version        = "";
                string   culture        = "";
                string   publicKeyToken = "";

                //If there is a version number we use it
                if (attributes.Count() >= 2)
                {
                    version = attributes[1].Replace("Version=", "").Trim();
                }
                if (attributes.Count() >= 3)
                {
                    culture = attributes[2].Replace("Culture=", "").Trim();
                }
                if (attributes.Count() >= 4)
                {
                    publicKeyToken = attributes[3].Replace("PublicKeyToken=", "").Trim();
                }

                AssemblyProject assemblyP = new AssemblyProject(name, version, culture, publicKeyToken);

                //Check if the AssemblyProject all ready exists.
                if (GetByGuid(assemblyP.Id) != null)
                {
                    assemblyP = GetByGuid(assemblyP.Id);
                }
                project.References.Add(assemblyP);

                //Add the referenced file as a AssemblyProject
                ProjectRepository.Instance.Add(assemblyP);
            }

            foreach (XmlElement el in doc.SelectNodes("/msbuild:Project/msbuild:ItemGroup/msbuild:ProjectReference", ns))
            {
                Project p = ProjectRepository.Instance.GetByGuid(new Guid(el.SelectSingleNode("msbuild:Project/text()", ns).Value));
                if (p != null)
                {
                    project.ProjectReferences.Add(p);
                }
                else
                {
                    try
                    {
                        p = ProjectRepository.Instance.FromFile(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(project.Path), el.SelectSingleNode("@Include", ns).Value));
                        project.ProjectReferences.Add(p);
                    }
                    catch (IOException)
                    {
                        project.MissingReferences.Add(new MissingProject(el.SelectSingleNode("@Include", ns).Value, el.SelectSingleNode("msbuild:Project/text()", ns).Value));
                    }
                }
            }
            return(project);
        }