Program.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Xml;
  7. namespace SynchProjects
  8. {
  9. class Program
  10. {
  11. static void CopyCompileFilesAsLinks(string platformName, string srcCsProj, string platformDest, string pathPrefix)
  12. {
  13. string dstCsProj = string.Format(platformDest, platformName);
  14. try
  15. {
  16. int warningCount = 0;
  17. const string XMLNS = "http://schemas.microsoft.com/developer/msbuild/2003";
  18. HashSet<string> linksDone = new HashSet<string>();
  19. Console.ForegroundColor = ConsoleColor.Gray;
  20. Console.WriteLine("Synch vsproj compiles {0} ...", Path.GetFileNameWithoutExtension(dstCsProj));
  21. XmlDocument xsrc = new XmlDocument();
  22. XmlDocument xdst = new XmlDocument();
  23. xsrc.Load(srcCsProj);
  24. xdst.Load(dstCsProj);
  25. XmlNamespaceManager sxns = new XmlNamespaceManager(xsrc.NameTable);
  26. XmlNamespaceManager dxns = new XmlNamespaceManager(xdst.NameTable);
  27. sxns.AddNamespace("ms", XMLNS);
  28. dxns.AddNamespace("ms", XMLNS);
  29. XmlElement srccont = xsrc.SelectSingleNode("/ms:Project/ms:ItemGroup[count(ms:Compile) != 0]", sxns) as XmlElement;
  30. XmlElement dstcont = xdst.SelectSingleNode("/ms:Project/ms:ItemGroup[count(ms:Compile) != 0]", dxns) as XmlElement;
  31. // dirty hack
  32. dstcont.InnerXml = srccont.InnerXml;
  33. List<XmlElement> toRemove = new List<XmlElement>();
  34. foreach (XmlElement xe in dstcont.ChildNodes.OfType<XmlElement>())
  35. {
  36. string file = xe.GetAttribute("Include");
  37. string link = Path.GetFileName(file);
  38. if (link.Contains(".g4"))
  39. {
  40. toRemove.Add(xe);
  41. continue;
  42. }
  43. if (!linksDone.Add(link))
  44. {
  45. ++warningCount;
  46. Console.ForegroundColor = ConsoleColor.Yellow;
  47. Console.WriteLine("\t[WARNING] - Duplicate file: {0}", link);
  48. }
  49. file = pathPrefix + file;
  50. xe.SetAttribute("Include", file);
  51. XmlElement xlink = xe.OwnerDocument.CreateElement("Link", XMLNS);
  52. xlink.InnerText = link;
  53. xe.AppendChild(xlink);
  54. }
  55. foreach (XmlElement xe in toRemove)
  56. xe.ParentNode.RemoveChild(xe);
  57. xdst.Save(dstCsProj);
  58. Console.ForegroundColor = ConsoleColor.Green;
  59. Console.WriteLine("\t[DONE] ({0} warnings)", warningCount);
  60. }
  61. catch (Exception ex)
  62. {
  63. Console.ForegroundColor = ConsoleColor.Red;
  64. Console.WriteLine("\t[ERROR] - {0}", ex.Message);
  65. }
  66. Console.WriteLine("\n");
  67. }
  68. static void Main(string[] args)
  69. {
  70. const string INTERPRETER_PROJECT = @"C:\git\moonsharp\src\MoonSharp.Interpreter\MoonSharp.Interpreter.net35-client.csproj";
  71. const string INTERPRETER_SUBPROJECTS_PATHS = @"C:\git\moonsharp\src\MoonSharp.Interpreter\_Projects\MoonSharp.Interpreter.{0}\MoonSharp.Interpreter.{0}.csproj";
  72. const string INTERPRETER_PATH_PREFIX = @"..\..\";
  73. const string TESTS_PROJECT = @"C:\git\moonsharp\src\MoonSharp.Interpreter.Tests\MoonSharp.Interpreter.Tests.net35-client.csproj";
  74. const string TESTS_SUBPROJECTS_PATHS = @"C:\git\moonsharp\src\MoonSharp.Interpreter.Tests\_Projects\MoonSharp.Interpreter.Tests.{0}\MoonSharp.Interpreter.Tests.{0}.csproj";
  75. const string TESTS_PATH_PREFIX = @"..\..\";
  76. string[] INTERPRETER_PLATFORMS = new string[] { "net40-client", "portable40" };
  77. string[] TESTS_PLATFORMS = new string[] { "net40-client", "portable40", "Embeddable.portable40" };
  78. foreach (string platform in INTERPRETER_PLATFORMS)
  79. CopyCompileFilesAsLinks(platform, INTERPRETER_PROJECT, INTERPRETER_SUBPROJECTS_PATHS, INTERPRETER_PATH_PREFIX);
  80. foreach (string platform in TESTS_PLATFORMS)
  81. CopyCompileFilesAsLinks(platform, TESTS_PROJECT, TESTS_SUBPROJECTS_PATHS, TESTS_PATH_PREFIX);
  82. Console.ReadLine();
  83. }
  84. }
  85. }