private bool SkipEnable(StrongNameConfiguration configuration) { if (!File.Exists(XmlFile)) { Log.LogError("The XmlFile given must exist."); return(false); } if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Log.LogError("Strongname tasks should only be run on Windows."); return(false); } bool printedHeader = false; foreach (RegistrySection section in WindowsRegistry.Sections) { using (RegistryKey registryKey = WindowsRegistry.CreateWritableVerificationRegistryKey(section)) { if (registryKey == null) { Log.LogError($"Unable to open writable verification registry key for {section}."); return(false); } foreach (var assembly in configuration.FilteredAssemblySpecifications[section]) { using (RegistryKey subKey = registryKey.OpenSubKey(assembly)) { if (subKey == null) { if (!printedHeader) { printedHeader = true; Log.LogMessage("Adding registry entries:"); } Log.LogMessage($" {registryKey}\\{assembly}"); registryKey.CreateSubKey(assembly); } } } } } if (!printedHeader) { Log.LogMessage("Skip Strong Names is already enabled."); } else { Log.LogMessage(""); Log.LogMessage("Skip Strong Names was successfully enabled."); } return(true); }
private bool SkipDisable(StrongNameConfiguration configuration) { bool printedHeader = false; foreach (RegistrySection section in WindowsRegistry.Sections) { using (RegistryKey registryKey = WindowsRegistry.CreateWritableVerificationRegistryKey(section)) { if (registryKey == null) { Log.LogError($"Unable to open writable verification registry key for {section}."); return(false); } foreach (var assembly in configuration.FilteredAssemblySpecifications[section]) { RegistryKey subKey = registryKey.OpenSubKey(assembly); if (subKey != null) { if (!printedHeader) { printedHeader = true; Log.LogMessage("Deleting registry entries:"); } Log.LogMessage($" {registryKey}\\{assembly}"); subKey.Dispose(); registryKey.DeleteSubKeyTree(assembly); } } } } if (!printedHeader) { Log.LogMessage("Skip Strong Names is already disabled."); } else { Log.LogMessage(""); Log.LogMessage("Skip Strong Names was successfully disabled."); } return(true); }