Prebuild.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #region BSD License
  2. /*
  3. Copyright (c) 2004-2005 Matthew Holmes ([email protected]), Dan Moorehead ([email protected])
  4. Redistribution and use in source and binary forms, with or without modification, are permitted
  5. provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright notice, this list of conditions
  7. and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions
  9. and the following disclaimer in the documentation and/or other materials provided with the
  10. distribution.
  11. * The name of the author may not be used to endorse or promote products derived from this software
  12. without specific prior written permission.
  13. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
  14. BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  15. ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  16. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  17. OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  18. OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  19. IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  20. */
  21. #endregion
  22. #region CVS Information
  23. /*
  24. * $Source$
  25. * $Author: kunnis $
  26. * $Date: 2009-04-14 21:33:14 -0400 (Tue, 14 Apr 2009) $
  27. * $Revision: 308 $
  28. */
  29. #endregion
  30. using System;
  31. using System.Collections.Specialized;
  32. using System.IO;
  33. using System.Reflection;
  34. using System.Runtime.InteropServices;
  35. using System.EnterpriseServices.Internal;
  36. using Prebuild.Core;
  37. using Prebuild.Core.Utilities;
  38. namespace Prebuild
  39. {
  40. /// <summary>
  41. ///
  42. /// </summary>
  43. class Prebuild
  44. {
  45. #region Main
  46. [STAThread]
  47. static void Main(string[] args)
  48. {
  49. Kernel kernel = null;
  50. try
  51. {
  52. kernel = Kernel.Instance;
  53. kernel.Initialize(LogTargets.File | LogTargets.Console, args);
  54. bool exit = false;
  55. if(kernel.CommandLine.WasPassed("usage"))
  56. {
  57. exit = true;
  58. OutputUsage();
  59. }
  60. if(kernel.CommandLine.WasPassed("showtargets"))
  61. {
  62. exit = true;
  63. OutputTargets(kernel);
  64. }
  65. if(kernel.CommandLine.WasPassed("install"))
  66. {
  67. exit = true;
  68. InstallAssembly(kernel);
  69. }
  70. if(kernel.CommandLine.WasPassed("remove"))
  71. {
  72. exit = true;
  73. RemoveAssembly(kernel);
  74. }
  75. if(!exit)
  76. {
  77. kernel.Process();
  78. }
  79. }
  80. #if !DEBUG
  81. catch (Exception ex)
  82. {
  83. Console.WriteLine("Unhandled error: {0}", ex.Message);
  84. Console.WriteLine("{0}", ex.StackTrace);
  85. }
  86. #endif
  87. finally
  88. {
  89. if(kernel != null && kernel.PauseAfterFinish)
  90. {
  91. Console.WriteLine("\nPress enter to continue...");
  92. Console.ReadLine();
  93. }
  94. }
  95. }
  96. #endregion
  97. #region Private Methods
  98. private static void InstallAssembly(Kernel kernel)
  99. {
  100. Publish publish = new Publish();
  101. string file = kernel.CommandLine["install"];
  102. //Console.WriteLine(".."+file+"..");
  103. publish.GacInstall(file);
  104. }
  105. private static void RemoveAssembly(Kernel kernel)
  106. {
  107. Publish publish = new Publish();
  108. string file = kernel.CommandLine["remove"];
  109. publish.GacRemove(file);
  110. }
  111. private static void OutputUsage()
  112. {
  113. Console.WriteLine("Usage: prebuild /target <target> [options]");
  114. Console.WriteLine("Available command-line switches:");
  115. Console.WriteLine();
  116. Console.WriteLine("/target Target for Prebuild");
  117. Console.WriteLine("/clean Clean the build files for the given target");
  118. Console.WriteLine("/file XML file to process");
  119. Console.WriteLine("/log Log file to write to");
  120. Console.WriteLine("/ppo Pre-process the file, but perform no other processing");
  121. Console.WriteLine("/pause Pauses the application after execution to view the output");
  122. Console.WriteLine("/yes Default to yes to any questions asked");
  123. Console.WriteLine("/install Install assembly into the GAC");
  124. Console.WriteLine("/remove Remove assembly from the GAC");
  125. Console.WriteLine();
  126. Console.WriteLine("See 'prebuild /showtargets for a list of available targets");
  127. Console.WriteLine("See readme.txt or check out http://dnpb.sourceforge.net for more information");
  128. Console.WriteLine();
  129. }
  130. private static void OutputTargets(Kernel kern)
  131. {
  132. Console.WriteLine("Targets available in Prebuild:");
  133. Console.WriteLine("");
  134. if(kern.Targets.Keys.Count > 0)
  135. {
  136. string[] targs = new string[kern.Targets.Keys.Count];
  137. kern.Targets.Keys.CopyTo(targs, 0);
  138. Array.Sort(targs);
  139. foreach(string target in targs)
  140. {
  141. Console.WriteLine(target);
  142. }
  143. }
  144. Console.WriteLine("");
  145. }
  146. #endregion
  147. }
  148. }