| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. |
| 2 | |
| 3 | namespace WixToolset.Harvesters |
| 4 | { |
| 5 | using System; |
| 6 | using System.Reflection; |
| 7 | using System.Runtime.InteropServices; |
| 8 | using Wix = WixToolset.Harvesters.Serialize; |
| 9 | |
| 10 | /// <summary> |
| 11 | /// Harvest WiX authoring from an assembly file. |
| 12 | /// </summary> |
| 13 | public sealed class AssemblyHarvester |
| 14 | { |
| 15 | /// <summary> |
| 16 | /// Harvest the registry values written by RegisterAssembly. |
| 17 | /// </summary> |
| 18 | /// <param name="path">The file to harvest registry values from.</param> |
| 19 | /// <returns>The harvested registry values.</returns> |
| 20 | public Wix.RegistryValue[] HarvestRegistryValues(string path) |
| 21 | { |
| 22 | #if NETCOREAPP |
| 23 | throw new PlatformNotSupportedException(); |
| 24 | #else |
| 25 | RegistrationServices regSvcs = new RegistrationServices(); |
| 26 | Assembly assembly = Assembly.LoadFrom(path); |
| 27 | |
| 28 | // must call this before overriding registry hives to prevent binding failures |
| 29 | // on exported types during RegisterAssembly |
| 30 | assembly.GetExportedTypes(); |
| 31 | |
| 32 | using (RegistryHarvester registryHarvester = new RegistryHarvester(true)) |
| 33 | { |
| 34 | regSvcs.RegisterAssembly(assembly, AssemblyRegistrationFlags.SetCodeBase); |
| 35 | |
| 36 | return registryHarvester.HarvestRegistry(); |
| 37 | } |
| 38 | #endif |
| 39 | } |
| 40 | } |
| 41 | } |