Пример #1
0
 /// <summary>
 /// Extracts a list of configuration files included in each project.
 /// </summary>
 public override void ExtractCandidateFiles()
 {
     foreach (String csprojFile in SourceFiles)
     {
         XElement projectFile = XElement.Load(csprojFile);
         String   baseDir     = Path.GetDirectoryName(csprojFile) + "\\";
         Uri      baseUri     = new Uri(baseDir);
         IEnumerable <XElement> itemGroupElements     = projectFile.Elements().Where(x => x.Name.LocalName == "ItemGroup");
         IEnumerable <XElement> noneOrContentElements = itemGroupElements.SelectMany(i => i.Elements().Where(r => (r.Name.LocalName.Equals("None") || r.Name.LocalName.Equals("Content"))));
         foreach (XElement noneOrContentElement in noneOrContentElements)
         {
             XAttribute includeAttribute = noneOrContentElement.Attribute("Include");
             if (includeAttribute != null && includeAttribute.Value.EndsWith(FileExtension, StringComparison.CurrentCultureIgnoreCase))
             {
                 Uri configUri = new Uri(baseUri, includeAttribute.Value);
                 if (!File.Exists(configUri.LocalPath))
                 {
                     String message = String.Format("Config file {0} referenced in {1} could not be found.", configUri.LocalPath, csprojFile);
                     throw new FileNotFoundException(message);
                 }
                 else if (!CandidateFiles.Contains(configUri.LocalPath))
                 {
                     CandidateFiles.Add(configUri.LocalPath);
                 }
             }
         }
     }
 }
Пример #2
0
        /// <summary>
        /// Extracts a list of csproje files included in each project.
        /// </summary>
        public override void ExtractCandidateFiles()
        {
            CandidateFiles.Clear();
            foreach (String solutionFile in SourceFiles)
            {
                String baseDir = Path.GetDirectoryName(solutionFile) + "\\";
                Uri    baseUri = new Uri(baseDir);

                String          solutionFileContents = File.ReadAllText(solutionFile);
                MatchCollection matches = projectRegex.Matches(solutionFileContents);
                foreach (Match match in matches)
                {
                    String[] parts = match.Value.Replace("\r\n", " ").Split(',');

                    if (parts != null && parts.Length > 1 && parts[1].Contains(FileExtension))
                    {
                        Uri csprojUri = new Uri(baseUri, parts[1].Replace("\"", ""));
                        if (!CandidateFiles.Contains(csprojUri.LocalPath))
                        {
                            CandidateFiles.Add(csprojUri.LocalPath);
                        }
                    }
                }
            }
        }