diff --git a/src/WingetCreateCLI/Commands/BaseCommand.cs b/src/WingetCreateCLI/Commands/BaseCommand.cs
index c6548542..c7e6ac17 100644
--- a/src/WingetCreateCLI/Commands/BaseCommand.cs
+++ b/src/WingetCreateCLI/Commands/BaseCommand.cs
@@ -424,19 +424,19 @@ protected static void DisplayManifestPreview(Manifests manifests)
/// Removes fields with empty string values from all manifests.
///
/// Wrapper object containing the manifest object models.
- protected static void RemoveEmptyStringFieldsInManifests(Manifests manifests)
+ protected static void RemoveEmptyStringAndListFieldsInManifests(Manifests manifests)
{
- RemoveEmptyStringFields(manifests.InstallerManifest);
- RemoveEmptyStringFields(manifests.DefaultLocaleManifest);
+ RemoveEmptyStringAndListFields(manifests.InstallerManifest);
+ RemoveEmptyStringAndListFields(manifests.DefaultLocaleManifest);
foreach (var localeManifest in manifests.LocaleManifests)
{
- RemoveEmptyStringFields(localeManifest);
+ RemoveEmptyStringAndListFields(localeManifest);
}
foreach (var installer in manifests.InstallerManifest.Installers)
{
- RemoveEmptyStringFields(installer);
+ RemoveEmptyStringAndListFields(installer);
}
}
@@ -824,13 +824,16 @@ protected string GetPRTitle(Manifests currentManifest, Manifests repositoryManif
}
///
- /// Removes fields with empty string values from a given object.
+ /// Removes fields with empty string and list values from a given object.
///
/// Object to remove empty string fields from.
- private static void RemoveEmptyStringFields(object obj)
+ private static void RemoveEmptyStringAndListFields(object obj)
{
var stringProperties = obj.GetType().GetProperties()
.Where(p => p.PropertyType == typeof(string));
+ var listProperties = obj.GetType().GetProperties()
+ .Where(p => p.PropertyType.IsGenericType &&
+ p.PropertyType.GetGenericTypeDefinition() == typeof(List<>));
foreach (var prop in stringProperties)
{
@@ -839,6 +842,14 @@ private static void RemoveEmptyStringFields(object obj)
prop.SetValue(obj, null);
}
}
+
+ foreach (var prop in listProperties)
+ {
+ if (prop.GetValue(obj) is IList list && list.Count == 0)
+ {
+ prop.SetValue(obj, null);
+ }
+ }
}
}
}
diff --git a/src/WingetCreateCLI/Commands/NewCommand.cs b/src/WingetCreateCLI/Commands/NewCommand.cs
index 169ff5e7..93670c72 100644
--- a/src/WingetCreateCLI/Commands/NewCommand.cs
+++ b/src/WingetCreateCLI/Commands/NewCommand.cs
@@ -255,7 +255,7 @@ public override async Task Execute()
PromptManifestProperties(manifests);
MergeNestedInstallerFilesIfApplicable(manifests.InstallerManifest);
ShiftInstallerFieldsToRootLevel(manifests.InstallerManifest);
- RemoveEmptyStringFieldsInManifests(manifests);
+ RemoveEmptyStringAndListFieldsInManifests(manifests);
DisplayManifestPreview(manifests);
isManifestValid = ValidateManifestsInTempDir(manifests);
}
diff --git a/src/WingetCreateCLI/Commands/UpdateCommand.cs b/src/WingetCreateCLI/Commands/UpdateCommand.cs
index d7f5bf0c..1c4926dd 100644
--- a/src/WingetCreateCLI/Commands/UpdateCommand.cs
+++ b/src/WingetCreateCLI/Commands/UpdateCommand.cs
@@ -263,7 +263,7 @@ await this.UpdateManifestsInteractively(initialManifests) :
return false;
}
- RemoveEmptyStringFieldsInManifests(updatedManifests);
+ RemoveEmptyStringAndListFieldsInManifests(updatedManifests);
ShiftInstallerFieldsToRootLevel(updatedManifests.InstallerManifest);
DisplayManifestPreview(updatedManifests);
diff --git a/src/WingetCreateTests/WingetCreateTests/Resources/TestPublisher.EmptyFields.yaml b/src/WingetCreateTests/WingetCreateTests/Resources/TestPublisher.EmptyFields.yaml
index 30082d1c..17c22718 100644
--- a/src/WingetCreateTests/WingetCreateTests/Resources/TestPublisher.EmptyFields.yaml
+++ b/src/WingetCreateTests/WingetCreateTests/Resources/TestPublisher.EmptyFields.yaml
@@ -14,6 +14,22 @@ Installers:
PackageFamilyName: ''
PrivacyUrl: ''
Author: ''
+Platform: []
+InstallModes: []
+FileExtensions: []
+Commands: []
+AppsAndFeaturesEntries: []
+Protocols: []
+Capabilities: []
+UnsupportedArguments: []
+UnsupportedOSArchitectures: []
+RestrictedCapabilities: []
+NestedInstallerFiles: []
+ExpectedReturnCodes: []
+Tags: []
+Agreements: []
+Documentations: []
+Icons: []
PackageLocale: en-US
ManifestType: singleton
-ManifestVersion: 1.0.0
\ No newline at end of file
+ManifestVersion: 1.6.0
\ No newline at end of file
diff --git a/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs b/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs
index 2e7d1924..9f516cf2 100644
--- a/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs
+++ b/src/WingetCreateTests/WingetCreateTests/UnitTests/UpdateCommandTests.cs
@@ -164,7 +164,7 @@ public async Task UpdateMultipleUrlManifests()
}
///
- /// Verifies that any fields with empty string values are replaced with null so that they do not appear in the manifest output.
+ /// Verifies that any fields with empty string and list values are replaced with null so that they do not appear in the manifest output.
///
/// A representing the asynchronous unit test.
[Test]
@@ -181,12 +181,31 @@ public async Task UpdateRemovesEmptyFields()
ClassicAssert.IsTrue(updatedManifestContents.Any(), "Updated manifests were not created successfully");
Manifests updatedManifests = Serialization.DeserializeManifestContents(updatedManifestContents);
+
+ // Empty string fields are removed
ClassicAssert.IsNull(updatedManifests.DefaultLocaleManifest.PrivacyUrl, "PrivacyUrl should be null.");
ClassicAssert.IsNull(updatedManifests.DefaultLocaleManifest.Author, "Author should be null.");
-
var firstInstaller = updatedManifests.InstallerManifest.Installers.First();
ClassicAssert.IsNull(firstInstaller.ProductCode, "ProductCode should be null.");
ClassicAssert.IsNull(firstInstaller.PackageFamilyName, "ProductCode should be null.");
+
+ // Empty list fields are removed
+ ClassicAssert.IsNull(updatedManifests.InstallerManifest.Platform, "Platform should be null.");
+ ClassicAssert.IsNull(updatedManifests.InstallerManifest.InstallModes, "InstallModes should be null.");
+ ClassicAssert.IsNull(updatedManifests.InstallerManifest.FileExtensions, "FileExtensions should be null.");
+ ClassicAssert.IsNull(updatedManifests.InstallerManifest.Commands, "Commands should be null.");
+ ClassicAssert.IsNull(updatedManifests.InstallerManifest.AppsAndFeaturesEntries, "AppsAndFeaturesEntries should be null.");
+ ClassicAssert.IsNull(updatedManifests.InstallerManifest.Protocols, "Protocols should be null.");
+ ClassicAssert.IsNull(updatedManifests.InstallerManifest.Capabilities, "Capabilities should be null.");
+ ClassicAssert.IsNull(updatedManifests.InstallerManifest.UnsupportedArguments, "UnsupportedArguments should be null.");
+ ClassicAssert.IsNull(updatedManifests.InstallerManifest.UnsupportedOSArchitectures, "UnsupportedOSArchitectures should be null.");
+ ClassicAssert.IsNull(updatedManifests.InstallerManifest.RestrictedCapabilities, "RestrictedCapabilities should be null.");
+ ClassicAssert.IsNull(updatedManifests.InstallerManifest.NestedInstallerFiles, "NestedInstallerFiles should be null.");
+ ClassicAssert.IsNull(updatedManifests.InstallerManifest.ExpectedReturnCodes, "ExpectedReturnCodes should be null.");
+ ClassicAssert.IsNull(updatedManifests.DefaultLocaleManifest.Tags, "Tags should be null.");
+ ClassicAssert.IsNull(updatedManifests.DefaultLocaleManifest.Agreements, "Agreements should be null.");
+ ClassicAssert.IsNull(updatedManifests.DefaultLocaleManifest.Documentations, "Documentations should be null.");
+ ClassicAssert.IsNull(updatedManifests.DefaultLocaleManifest.Icons, "Icons should be null.");
}
///