Skip to content

Commit f7c203e

Browse files
committed
(chocolatey#2503) Export via serialization of class
Instead of exporting via building an xml document manually, this creates a PackagesConfigFilePackageSetting and serializes that to create the xml document that is saved. This allows for usage of the same class as is used to read in packages.config files to export those files. The reason the various "Specified" members are added to the PackagesConfigFilePackageSetting class is so if an element is not set during export, it will not show up at all in the resulting serialized packages.config file. # Conflicts: # src/chocolatey/infrastructure.app/commands/ChocolateyExportCommand.cs
1 parent deea54d commit f7c203e

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/chocolatey/infrastructure.app/commands/ChocolateyExportCommand.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,12 +182,12 @@ public void Run(ChocolateyConfiguration configuration)
182182

183183
xw.WriteAttributeString("sourceType", "nuget");
184184

185-
xw.WriteEndElement();
185+
packagesConfig.Packages.Add(packageElement);
186186
}
187187

188188
if (configuration.ExportCommand.IncludeRegistryPrograms)
189189
{
190-
var itemsToRemoveFromMachine = packageResults.Select(package => _packageInfoService.Get(package.PackageMetadata)).Where(p => p.RegistrySnapshot != null).ToList();
190+
var itemsToRemoveFromMachine = installedPackages.Select(package => _packageInfoService.Get(package.PackageMetadata)).Where(p => p.RegistrySnapshot != null).ToList();
191191

192192
var machineInstalled = _registryService.GetInstallerKeys().RegistryKeys.Where(
193193
p => p.IsInProgramsAndFeatures() &&
@@ -231,8 +231,10 @@ public void Run(ChocolateyConfiguration configuration)
231231
}
232232
}
233233

234-
xw.WriteEndElement();
235-
xw.Flush();
234+
var ns = new XmlSerializerNamespaces();
235+
ns.Add("", "");
236+
var packagesConfigSerializer = new XmlSerializer(typeof(PackagesConfigFileSettings));
237+
packagesConfigSerializer.Serialize(xw, packagesConfig, ns);
236238
}
237239

238240
var fullOutputFilePath = _fileSystem.GetFullPath(configuration.ExportCommand.OutputFilePath);

src/chocolatey/infrastructure.app/services/INugetService.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,12 @@ public interface INugetService : ISourceRunner
6161
/// <param name="packageName">Name of the package.</param>
6262
void EnsureBackupDirectoryRemoved(string packageName);
6363

64-
<<<<<<< HEAD
65-
=======
66-
6764
/// <summary>
6865
/// Get all installed packages
6966
/// </summary>
7067
/// <param name="config">The configuration</param>
7168
IEnumerable<PackageResult> GetInstalledPackages(ChocolateyConfiguration config);
7269

73-
7470
/// <summary>
7571
/// Gets the configuration from remembered arguments
7672
/// </summary>
@@ -80,7 +76,6 @@ public interface INugetService : ISourceRunner
8076
ChocolateyConfiguration GetPackageConfigFromRememberedArguments(ChocolateyConfiguration config,
8177
ChocolateyPackageInformation packageInfo);
8278

83-
>>>>>>> 85ab9168 ((#2886) Switch remembered args to only change local configuration)
8479
#pragma warning disable IDE0022, IDE1006
8580
[Obsolete("This overload is deprecated and will be removed in v3.")]
8681
ConcurrentDictionary<string, PackageResult> get_outdated(ChocolateyConfiguration config);

0 commit comments

Comments
 (0)