DotNetConfigHelper.cs 1.7 KB

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