Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

78 lignes
2.8 KiB

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