GetMsiProperty.cs 932 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. #if BUILD_MSI_TASKS
  4. using System;
  5. using Microsoft.Build.Framework;
  6. using Microsoft.Build.Utilities;
  7. using Microsoft.Deployment.WindowsInstaller.Package;
  8. namespace RepoTasks;
  9. public class GetMsiProperty : Microsoft.Build.Utilities.Task
  10. {
  11. [Required]
  12. public string InstallPackage { get; set; }
  13. [Required]
  14. public string Property { get; set; }
  15. [Output]
  16. public string Value { get; set; }
  17. public override bool Execute()
  18. {
  19. try
  20. {
  21. using (var package = new InstallPackage(InstallPackage, 0))
  22. {
  23. Value = package.Property[Property];
  24. }
  25. }
  26. catch (Exception exception)
  27. {
  28. Log.LogErrorFromException(exception);
  29. }
  30. return !Log.HasLoggedErrors;
  31. }
  32. }
  33. #endif