void SetRecordMsiProperties(WorkloadPackRecord record, RegistryKey key) { record.ProviderKeyName = (string)key.GetValue("DependencyProviderKey"); record.ProductCode = (string)key.GetValue("ProductCode"); record.ProductVersion = new Version((string)key.GetValue("ProductVersion")); record.UpgradeCode = (string)key.GetValue("UpgradeCode"); }
/// <summary> /// Detect installed workload pack records. Only the default registry hive is searched. Finding a workload pack /// record does not necessarily guarantee that the MSI is installed. /// </summary> private IReadOnlyDictionary <string, List <WorkloadPackRecord> > GetWorkloadPackRecords() { Log?.LogMessage("Detecting installed workload packs."); Dictionary <string, List <WorkloadPackRecord> > workloadPackRecords = new Dictionary <string, List <WorkloadPackRecord> >(); using RegistryKey installedPacksKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\dotnet\InstalledPacks"); if (installedPacksKey != null) { foreach (string packId in installedPacksKey.GetSubKeyNames()) { if (!workloadPackRecords.ContainsKey(packId)) { workloadPackRecords[packId] = new List <WorkloadPackRecord>(); } using RegistryKey packKey = installedPacksKey.OpenSubKey(packId); foreach (string packVersion in packKey.GetSubKeyNames()) { using RegistryKey packVersionKey = packKey.OpenSubKey(packVersion); WorkloadPackRecord record = new WorkloadPackRecord { ProviderKeyName = (string)packVersionKey.GetValue("DependencyProviderKey"), PackId = new NET.Sdk.WorkloadManifestReader.WorkloadPackId(packId), PackVersion = new NuGetVersion(packVersion), ProductCode = (string)packVersionKey.GetValue("ProductCode"), ProductVersion = new Version((string)packVersionKey.GetValue("ProductVersion")), UpgradeCode = (string)packVersionKey.GetValue("UpgradeCode"), }; Log?.LogMessage($"Found workload pack record, Id: {record.PackId}, version: {record.PackVersion}, ProductCode: {record.ProductCode}, provider key: {record.ProviderKeyName}"); workloadPackRecords[packId].Add(record); } } } return(new ReadOnlyDictionary <string, List <WorkloadPackRecord> >(workloadPackRecords)); }
/// <summary> /// Creates the log filename to use when executing an MSI. The name is based on the primary log, workload pack record and <see cref="InstallAction"/>. /// </summary> /// <param name="record">The workload record to use when generating the log name.</param> /// <param name="action">The install action that will be performed.</param> /// <returns>The full path of the log file.</returns> protected string GetMsiLogName(WorkloadPackRecord record, InstallAction action) { return(Path.Combine(Path.GetDirectoryName(Log.LogPath), Path.GetFileNameWithoutExtension(Log.LogPath) + $"_{record.PackId}-{record.PackVersion}_{action}.log")); }