GetMsiProperty.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #if BUILD_MSI_TASKS
  2. // Copyright (c) .NET Foundation. All rights reserved.
  3. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
  4. using System;
  5. using Microsoft.Build.Framework;
  6. using Microsoft.Build.Utilities;
  7. using Microsoft.Deployment.WindowsInstaller.Package;
  8. namespace RepoTasks
  9. {
  10. public class GetMsiProperty : Task
  11. {
  12. [Required]
  13. public string InstallPackage { get; set; }
  14. [Required]
  15. public string Property { get; set; }
  16. [Output]
  17. public string Value { get; set; }
  18. public override bool Execute()
  19. {
  20. try
  21. {
  22. using (var package = new InstallPackage(InstallPackage, 0))
  23. {
  24. Value = package.Property[Property];
  25. }
  26. }
  27. catch (Exception exception)
  28. {
  29. Log.LogErrorFromException(exception);
  30. }
  31. return !Log.HasLoggedErrors;
  32. }
  33. }
  34. }
  35. #endif