Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 

81 rader
2.8 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using FlubuCore.Context;
  5. using FlubuCore.IO;
  6. using FlubuCore.Scripting;
  7. using FlubuCore.Scripting.Attributes;
  8. using GlobExpressions;
  9. namespace BuildScript
  10. {
  11. [Include("./build/BuildVersion.cs")]
  12. public partial class BuildScript : DefaultBuildScript
  13. {
  14. private const string ArtifactsDir = "./artifacts";
  15. [FromArg("c|configuration")]
  16. public string Configuration { get; set; }
  17. protected BuildVersion BuildVersion { get; set; }
  18. protected List<FileFullPath> ProjectFiles { get; set; }
  19. protected List<FileFullPath> TestProjectFiles { get; set; }
  20. protected override void ConfigureBuildProperties(IBuildPropertiesContext context)
  21. {
  22. context.Properties.Set(BuildProps.SolutionFileName, "CAP.sln");
  23. context.Properties.Set(BuildProps.BuildConfiguration, string.IsNullOrEmpty(Configuration) ? "Release" : Configuration);
  24. }
  25. protected override void BeforeBuildExecution(ITaskContext context)
  26. {
  27. BuildVersion = FetchBuildVersion(context);
  28. TestProjectFiles = context.GetFiles("./test", "*/*.csproj");
  29. ProjectFiles = context.GetFiles("./src", "*/*.csproj");
  30. }
  31. protected override void ConfigureTargets(ITaskContext context)
  32. {
  33. var clean = context.CreateTarget("Clean")
  34. .SetDescription("")
  35. .AddCoreTask(x => x.Clean()
  36. .AddDirectoryToClean(ArtifactsDir, true));
  37. var restore = context.CreateTarget("Restore")
  38. .DependsOn(clean)
  39. .AddCoreTask(x => x.Restore());
  40. var build = context.CreateTarget("Build")
  41. .DependsOn(restore)
  42. .AddCoreTask(x => x.Build()
  43. .InformationalVersion(BuildVersion.VersionWithSuffix()));
  44. var tests = context.CreateTarget("Tests")
  45. .ForEach(TestProjectFiles,
  46. (projectFile, target) =>
  47. {
  48. target.AddCoreTask(x => x.Test()
  49. .Project(projectFile)
  50. .NoBuild());
  51. });
  52. var pack = context.CreateTarget("Pack")
  53. .ForEach(ProjectFiles, (projectFile, target) =>
  54. {
  55. target.AddCoreTask(x => x.Pack()
  56. .NoBuild()
  57. .Project(projectFile)
  58. .IncludeSymbols()
  59. .VersionSufix(BuildVersion.Suffix)
  60. .OutputDirectory(ArtifactsDir));
  61. });
  62. context.CreateTarget("Default")
  63. .SetAsDefault()
  64. .DependsOn(clean, restore, build, tests, pack);
  65. }
  66. }
  67. }