Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Xml;
- using System.Xml.Linq;
- namespace ConsoleApplication1
- {
- class Program
- {
- public class MyConfig
- {
- public string DisplayName { get; set; }
- public string IsDebugOnly { get; set; }
- public string IsReleaseOnly { get; set; }
- public string PackageFilesAs { get; set; }
- public string ShouldBuild { get; set; }
- }
- public static void Main(string[] args)
- {
- var ConfigsFound = new List<MyConfig>();
- string[] allLines = System.IO.File.ReadAllLines(@"C:\foo.vdproj");
- int configStartIndex = 0;
- List<int> configNameAt = new List<int>();
- for (int i = 0; i < allLines.Length - 1; i++)
- {
- string line = allLines[i];
- if (string.IsNullOrWhiteSpace(line))
- continue;
- //parse out the configurations in this vdproj
- if (line == "\t\"Configurations\"")
- {
- //read ahead to determine the end of the config block.
- configStartIndex = i;
- }
- if (line.StartsWith("\t\t\""))
- {
- //this is the beginning of a named configuration.
- configNameAt.Add(i);
- }
- if (line == "\t}" && configStartIndex>0)
- {
- //end of config section; crater out!
- break;
- }
- }
- //build a list of config sections!
- foreach (int configStartLine in configNameAt)
- {
- int propertiesStartAt = configStartLine + 3;
- MyConfig config = new MyConfig { DisplayName = GetValueFromLine(propertiesStartAt) };
- config.IsDebugOnly = GetValueFromLine(propertiesStartAt + 1);
- config.IsReleaseOnly = GetValueFromLine(propertiesStartAt + 2);
- config.PackageFilesAs = GetValueFromLine(propertiesStartAt + 3);
- config.ShouldBuild = GetValueFromLine(propertiesStartAt + 4);
- ConfigsFound.Add(config);
- }
- foreach (var item in ConfigsFound)
- {
- Console.WriteLine(item.DisplayName + " " + item.IsDebugOnly);
- }
- Console.ReadLine();
- }
- private static string GetValueFromLine(int lineNumber)
- {
- string lineText = System.IO.File.ReadAllLines(@"C:\foo.vdproj").Skip(lineNumber-1).Take(1).SingleOrDefault();
- // now have something like " DisplayName = "8:Release""
- lineText = lineText.Trim().Replace(" = ", "=");
- return lineText.Split('=')[1].Trim('"');
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement