using System; using System.Xml; using System.IO; namespace CopyProject { /// /// Simple class which opens a project file, updates the GUIDs /// in it, and writes it out to a new name. Copying a Visual Studio.NET /// project file without replacing the GUIDs will cause problems. /// Free for any use, author: Steve Tibbett (stevex-code@oakburl.net) /// class MainClass { /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { MainClass c = new MainClass(); c.Run(args); } // Create a new GUID string formatted the usual way. string NewGuidString() { return "{" + System.Guid.NewGuid().ToString().ToUpper() + "}"; } // This is the main entry point for the "object" that runs // this program; the Main entry point is static. void Run(string[] args) { if (args.Length < 2) { Console.WriteLine("Please supply a source and destination file name (*.vcproj)."); return; } // Read the source file XmlDocument doc = new XmlDocument(); try { // Load the existing project file. doc.Load(args[0]); } catch (Exception ex) { // Oops Console.WriteLine("Exception reading project file:"); Console.WriteLine(ex.Message); return; }; try { // Replace the ProjectGUID XmlNode node = doc.SelectSingleNode("/VisualStudioProject"); node.Attributes["ProjectGUID"].Value = NewGuidString(); // Replace the UniqueIdentifier GUIDs in the Filter nodes XmlNodeList nodes = doc.SelectNodes("//Filter"); foreach (XmlNode filterNode in nodes) { XmlAttribute attr = filterNode.Attributes["UniqueIndentifier"]; if (attr != null) { attr.Value = NewGuidString(); }; } } catch (Exception ex) { Console.WriteLine("Error updating GUIDs:"); Console.WriteLine(ex.Message); return; } try { // Write out the updated project file doc.Save(args[1]); } catch (Exception ex) { Console.WriteLine("Error saving output file:"); Console.WriteLine(ex.Message); return; }; Console.WriteLine("Done!"); } } }