GenerateGuid.cs 890 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. using System;
  4. using System.Linq;
  5. using Microsoft.Build.Framework;
  6. using Microsoft.Build.Utilities;
  7. namespace RepoTasks;
  8. public class GenerateGuid : Microsoft.Build.Utilities.Task
  9. {
  10. [Output]
  11. public string Guid { get; private set; }
  12. [Required]
  13. public string NamespaceGuid { get; set; }
  14. [Required]
  15. public ITaskItem[] Values { get; set; }
  16. public override bool Execute()
  17. {
  18. try
  19. {
  20. var value = string.Join(",", Values.Select(o => o.ItemSpec).ToArray()).ToLowerInvariant();
  21. Guid = Uuid.Create(new Guid(NamespaceGuid), value).ToString();
  22. }
  23. catch (Exception e)
  24. {
  25. Log.LogErrorFromException(e);
  26. }
  27. return !Log.HasLoggedErrors;
  28. }
  29. }