DotNetConfigHelper.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System.Globalization;
  2. using JetBrains.Annotations;
  3. using Nuke.Common.Tools.DotNet;
  4. // ReSharper disable ReturnValueOfPureMethodIsNotUsed
  5. public class DotNetConfigHelper
  6. {
  7. public DotNetBuildSettings Build;
  8. public DotNetPackSettings Pack;
  9. public DotNetTestSettings Test;
  10. public DotNetConfigHelper(DotNetBuildSettings s)
  11. {
  12. Build = s;
  13. }
  14. public DotNetConfigHelper(DotNetPackSettings s)
  15. {
  16. Pack = s;
  17. }
  18. public DotNetConfigHelper(DotNetTestSettings s)
  19. {
  20. Test = s;
  21. }
  22. public DotNetConfigHelper AddProperty(string key, bool value) =>
  23. AddProperty(key, value.ToString(CultureInfo.InvariantCulture).ToLowerInvariant());
  24. public DotNetConfigHelper AddProperty(string key, string value)
  25. {
  26. Build = Build?.AddProperty(key, value);
  27. Pack = Pack?.AddProperty(key, value);
  28. Test = Test?.AddProperty(key, value);
  29. return this;
  30. }
  31. public DotNetConfigHelper SetConfiguration(string configuration)
  32. {
  33. Build = Build?.SetConfiguration(configuration);
  34. Pack = Pack?.SetConfiguration(configuration);
  35. Test = Test?.SetConfiguration(configuration);
  36. return this;
  37. }
  38. public DotNetConfigHelper SetVerbosity(DotNetVerbosity verbosity)
  39. {
  40. Build = Build?.SetVerbosity(verbosity);
  41. Pack = Pack?.SetVerbostiy(verbosity);
  42. Test = Test?.SetVerbosity(verbosity);
  43. return this;
  44. }
  45. public static implicit operator DotNetConfigHelper(DotNetBuildSettings s) => new DotNetConfigHelper(s);
  46. public static implicit operator DotNetConfigHelper(DotNetPackSettings s) => new DotNetConfigHelper(s);
  47. public static implicit operator DotNetConfigHelper(DotNetTestSettings s) => new DotNetConfigHelper(s);
  48. }