Helpers.cs 533 B

123456789101112131415161718192021222324
  1. using System;
  2. using System.IO;
  3. using Nuke.Common.Utilities;
  4. class Helpers
  5. {
  6. public static IDisposable UseTempDir(out string dir)
  7. {
  8. var path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
  9. Directory.CreateDirectory(path);
  10. dir = path;
  11. return DelegateDisposable.CreateBracket(null, () =>
  12. {
  13. try
  14. {
  15. Directory.Delete(path, true);
  16. }
  17. catch
  18. {
  19. // ignore
  20. }
  21. });
  22. }
  23. }