25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

BuildScript.cs 3.1 KiB

4 yıl önce
4 yıl önce
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System.Collections.Generic;
  2. using FlubuCore.Context;
  3. using FlubuCore.Context.Attributes.BuildProperties;
  4. using FlubuCore.IO;
  5. using FlubuCore.Scripting;
  6. using FlubuCore.Scripting.Attributes;
  7. namespace BuildScript
  8. {
  9. [Include("./build/BuildVersion.cs")]
  10. public partial class BuildScript : DefaultBuildScript
  11. {
  12. [FromArg("c|configuration")]
  13. [BuildConfiguration]
  14. public string Configuration { get; set; } = "Release";
  15. [SolutionFileName] public string SolutionFileName { get; set; } = "CAP.sln";
  16. protected BuildVersion BuildVersion { get; set; }
  17. protected string ArtifactsDir => RootDirectory.CombineWith("artifacts");
  18. protected List<FileFullPath> ProjectFiles { get; set; }
  19. protected List<FileFullPath> TestProjectFiles { get; set; }
  20. protected override void BeforeBuildExecution(ITaskContext context)
  21. {
  22. BuildVersion = FetchBuildVersion(context);
  23. TestProjectFiles = context.GetFiles(RootDirectory.CombineWith("test"), "*/*.csproj");
  24. ProjectFiles = context.GetFiles(RootDirectory.CombineWith("src"), "*/*.csproj");
  25. }
  26. protected override void ConfigureTargets(ITaskContext context)
  27. {
  28. var clean = context.CreateTarget("Clean")
  29. .SetDescription("Cleans the output of all projects in the solution.")
  30. .AddCoreTask(x => x.Clean()
  31. .AddDirectoryToClean(ArtifactsDir, true));
  32. var restore = context.CreateTarget("Restore")
  33. .SetDescription("Restores the dependencies and tools of all projects in the solution.")
  34. .DependsOn(clean)
  35. .AddCoreTask(x => x.Restore());
  36. var build = context.CreateTarget("Build")
  37. .SetDescription("Builds all projects in the solution.")
  38. .DependsOn(restore)
  39. .AddCoreTask(x => x.Build()
  40. .InformationalVersion(BuildVersion.VersionWithSuffix()));
  41. var tests = context.CreateTarget("Tests")
  42. .SetDescription("Runs all Cap tests.")
  43. .ForEach(TestProjectFiles,
  44. (projectFile, target) =>
  45. {
  46. target.AddCoreTask(x => x.Test()
  47. .Project(projectFile)
  48. .NoBuild());
  49. });
  50. var pack = context.CreateTarget("Pack")
  51. .SetDescription("Creates nuget packages for Cap.")
  52. .ForEach(ProjectFiles, (projectFile, target) =>
  53. {
  54. target.AddCoreTask(x => x.Pack()
  55. .NoBuild()
  56. .Project(projectFile)
  57. .IncludeSymbols()
  58. .VersionSuffix(BuildVersion.Suffix)
  59. .OutputDirectory(ArtifactsDir));
  60. });
  61. context.CreateTarget("Default")
  62. .SetDescription("Runs all targets.")
  63. .SetAsDefault()
  64. .DependsOn(clean, restore, build, tests, pack);
  65. }
  66. }
  67. }