Exemple #1
0
        public IEnumerable<VSProject> GetProjects()
        {
            List<string> projFilePaths = ExtractProjects(pathToSolutionFile);
              var projectItems = new ConcurrentBag<VSProject>();

              // let's do sequential for now
              //foreach (var pf in projFilePaths)
              Parallel.ForEach(projFilePaths, pf =>
              {
            if (File.Exists(pf))
            {
              IDictionary<string, string> props = new Dictionary<string, string>();
              props.Add("Configuration", "Debug");
              props.Add("Platform", "x64");
              var projInst = new ProjectInstance(pf, props, "4.0");
              var pi = projInst.ToProjectItem();
              projectItems.Add(pi);
            }
              });

              return projectItems;
        }
        public static List<ProjectCreator.ProjectReference> GetProjectReferences(this ProjectInstance p)
        {
            var references = new List<ProjectCreator.ProjectReference>();
              foreach (var i in p.Items)
              {
            if (i.ItemType.Equals("ProjectReference"))
            {
              var proj = i.Metadata.SingleOrDefault(z => z.Name.Equals("Project"));
              if (proj != null)
              {
            references.Add(new ProjectCreator.ProjectReference{
              Id=Guid.Parse(proj.EvaluatedValue),
              FileName = i.EvaluatedInclude
            });
              }
              else
              {
            var include = i.EvaluatedInclude;
            // try to get physical file and projectguid from that
            string dir = Path.GetDirectoryName(p.FullPath);
            string projPath = Path.GetFullPath(Path.Combine(dir, include));
            if (File.Exists(projPath))
            {
              var pi = new ProjectInstance(projPath);
              var item = pi.ToProjectItem();
              references.Add(new ProjectCreator.ProjectReference {Id = item.ProjectGuid, FileName = projPath});
            }
            else
            {
              // hack: just don't reference this
              //throw new Exception("Project " + p.FullPath + " references non-existent project " + projPath);
            }
              }
            }
              }

              return references;
        }