Program.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using System;
  2. using System.Collections;
  3. using System.IO;
  4. using System.Linq;
  5. using Microsoft.Build.Framework;
  6. namespace Avalonia.Build.Tasks
  7. {
  8. public class Program
  9. {
  10. static int Main(string[] args)
  11. {
  12. if (args.Length != 3)
  13. {
  14. if (args.Length == 1)
  15. args = new[] {"original.dll", "references", "out.dll"}
  16. .Select(x => Path.Combine(args[0], x)).ToArray();
  17. else
  18. {
  19. Console.Error.WriteLine("input references output");
  20. return 1;
  21. }
  22. }
  23. return new CompileAvaloniaXamlTask()
  24. {
  25. AssemblyFile = args[0],
  26. ReferencesFilePath = args[1],
  27. OutputPath = args[2],
  28. BuildEngine = new ConsoleBuildEngine(),
  29. ProjectDirectory = Directory.GetCurrentDirectory()
  30. }.Execute() ?
  31. 0 :
  32. 2;
  33. }
  34. class ConsoleBuildEngine : IBuildEngine
  35. {
  36. public void LogErrorEvent(BuildErrorEventArgs e)
  37. {
  38. Console.WriteLine($"ERROR: {e.Code} {e.Message} in {e.File} {e.LineNumber}:{e.ColumnNumber}-{e.EndLineNumber}:{e.EndColumnNumber}");
  39. }
  40. public void LogWarningEvent(BuildWarningEventArgs e)
  41. {
  42. Console.WriteLine($"WARNING: {e.Code} {e.Message} in {e.File} {e.LineNumber}:{e.ColumnNumber}-{e.EndLineNumber}:{e.EndColumnNumber}");
  43. }
  44. public void LogMessageEvent(BuildMessageEventArgs e)
  45. {
  46. Console.WriteLine($"MESSAGE: {e.Code} {e.Message} in {e.File} {e.LineNumber}:{e.ColumnNumber}-{e.EndLineNumber}:{e.EndColumnNumber}");
  47. }
  48. public void LogCustomEvent(CustomBuildEventArgs e)
  49. {
  50. Console.WriteLine($"CUSTOM: {e.Message}");
  51. }
  52. public bool BuildProjectFile(string projectFileName, string[] targetNames, IDictionary globalProperties,
  53. IDictionary targetOutputs) => throw new NotSupportedException();
  54. public bool ContinueOnError { get; }
  55. public int LineNumberOfTaskNode { get; }
  56. public int ColumnNumberOfTaskNode { get; }
  57. public string ProjectFileOfTaskNode { get; }
  58. }
  59. }
  60. }