/*============================================================================= Project: SharpImage Module: ConfigureProject/Program.cs Language: C# Author: Dan Mueller Date: $Date: 2007-09-01 06:17:25 +1000 (Sat, 01 Sep 2007) $ Revision: $Revision: 2 $ Copyright (c) Queensland University of Technology (QUT) 2007. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =============================================================================*/ using System; using System.IO; using System.Collections; using System.Collections.Generic; using System.Text; namespace ConfigureProject { class Program { static void Main(string[] args) { try { // args[0] = Full solution path // args[1] = Replacement0 (eg. Release:ExceptionHandling="FALSE":ExceptionHandling="2") // args[2] = Replacement1 (eg. Debug:BasicRuntimeChecks="3":BasicRuntimeChecks="0") if (args.Length <= 1) { Console.WriteLine("Usage: AbsoluteSolutionPath Replacement0 [Replacement1] [Replacement2] [...]"); return; } // Get replacements from command line string pathSolution = args[0]; List replacements = new List(); for (int i=1; i replacements) { bool isInConfiguration = false; string currentConfigurationName = string.Empty; // Check that the project exists if (!File.Exists(pathProject)) { Console.WriteLine("Skipping " + Path.GetFileName(pathProject) + " because the path does not exist..."); return; } // Open project for reading and get text string bodyProject = File.ReadAllText(pathProject); bodyProject = bodyProject.Replace("\r\n", "\r"); string[] linesProject = bodyProject.Split('\r'); // Open project for writing StreamWriter writer = new StreamWriter(pathProject); // Output the adjusted/configured project foreach (string lineProject in linesProject) { string lineProjectFinal = lineProject; if (lineProject.Contains("")) isInConfiguration = true; else if (lineProject.Contains("")) { isInConfiguration = false; currentConfigurationName = string.Empty; } else if (isInConfiguration && currentConfigurationName == string.Empty && lineProject.Contains("Name=")) { currentConfigurationName = lineProject; currentConfigurationName = currentConfigurationName.Replace("Name=", ""); currentConfigurationName = currentConfigurationName.Trim('\t', '"', ' '); } if (isInConfiguration && currentConfigurationName != string.Empty) { foreach (string replacement in replacements) { // Get the replacement info string[] replacementInfo = replacement.Split(':'); if (replacementInfo.Length != 3) throw new ApplicationException("Invalid replacement information: " + replacement); if (currentConfigurationName.StartsWith(replacementInfo[0])) { // We are in the desired configuration lineProjectFinal = lineProjectFinal.Replace(replacementInfo[1], replacementInfo[2]); } } } // Write the final line writer.WriteLine(lineProjectFinal); } // Clean up writer.Flush(); writer.Close(); Console.WriteLine("Done."); } } }