diff --git a/tools/Tools.Common/Models/ModuleMetadata.cs b/tools/Tools.Common/Models/ModuleMetadata.cs index 561927fd3bc9..a068aa372705 100644 --- a/tools/Tools.Common/Models/ModuleMetadata.cs +++ b/tools/Tools.Common/Models/ModuleMetadata.cs @@ -99,7 +99,7 @@ public override bool Equals(Object obj) public static ModuleMetadata DeserializeCmdlets(string fileName) { - return JsonConvert.DeserializeObject(File.ReadAllText(fileName)); + return File.Exists(fileName) ? JsonConvert.DeserializeObject(File.ReadAllText(fileName)) : null; } public override int GetHashCode() diff --git a/tools/VersionController/Models/VersionMetadataHelper.cs b/tools/VersionController/Models/VersionMetadataHelper.cs index 7d886545e863..ef71fc468ad5 100644 --- a/tools/VersionController/Models/VersionMetadataHelper.cs +++ b/tools/VersionController/Models/VersionMetadataHelper.cs @@ -50,7 +50,7 @@ public VersionMetadataHelper(VersionFileHelper fileHelper) /// private ModuleMetadata DeserializeCmdlets(string fileName) { - return JsonConvert.DeserializeObject(File.ReadAllText(fileName)); + return File.Exists(fileName) ? JsonConvert.DeserializeObject(File.ReadAllText(fileName)) : null; } /// @@ -58,7 +58,7 @@ private ModuleMetadata DeserializeCmdlets(string fileName) /// /// Name of the file cmdlets are being serialized to. /// List of cmdlets that are to be serialized. - public static void SerializeCmdlets(string fileName, ModuleMetadata moduleMetadata) + public static string SerializeCmdlets(string fileName, ModuleMetadata moduleMetadata) { string json = JsonConvert.SerializeObject(moduleMetadata, new JsonSerializerSettings { @@ -67,6 +67,7 @@ public static void SerializeCmdlets(string fileName, ModuleMetadata moduleMetada ContractResolver = VersionMetadataContractResolver.Instance }); File.WriteAllText(fileName, json); + return fileName; } /// @@ -297,7 +298,8 @@ public Version GetVersionBumpUsingSerialized() Console.WriteLine($"Warning: {moduleName} does not have a previously serialized cmdlet for comparison."); Console.ForegroundColor = currentColor; var newCmdletFile = Path.Join(serializedCmdletsDirectory, serializedCmdletName); - SerializeCmdlets(newCmdletFile, newModuleMetadata); + // Use newly build one, only bump PATCH version + serializedCmdletFile = SerializeCmdlets(newCmdletFile, newModuleMetadata); } var oldModuleMetadata = DeserializeCmdlets(serializedCmdletFile); CmdletLoader.ModuleMetadata = oldModuleMetadata;