Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Convert reg-free com manifest generation to System.Text.Json.
  • Loading branch information
jkoritzinsky committed Apr 5, 2019
commit ed58b77f0371ff57bc652db3e47c88c015d1b191
18 changes: 7 additions & 11 deletions src/Tasks/Microsoft.NET.Build.Tasks/RegFreeComManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
using System.Text;
using System.Xml;
using System.Xml.Linq;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Text.Json;

namespace Microsoft.NET.Build.Tasks
{
Expand All @@ -22,7 +21,7 @@ internal static class RegFreeComManifest
/// <param name="assemblyVersion">The version of the assembly.</param>
/// <param name="clsidMapPath">The path to the clasidmap file.</param>
/// <param name="comManifestPath">The path to which to write the manifest.</param>
public static void CreateManifestFromClsidmap(string assemblyName, string comHostName, string assemblyVersion, string clsidMapPath, string comManifestPath)
private static void CreateManifestFromClsidmap(string assemblyName, string comHostName, string assemblyVersion, string clsidMapPath, string comManifestPath)
{
XNamespace ns = "urn:shemas-microsoft-com:asm.v1";

Expand All @@ -34,18 +33,15 @@ public static void CreateManifestFromClsidmap(string assemblyName, string comHos

XElement fileElement = new XElement(ns + "file", new XAttribute("name", comHostName));

JObject clsidMap;
string clsidMapText = File.ReadAllText(clsidMapPath);
using (StreamReader clsidMapReader = File.OpenText(clsidMapPath))
using (JsonTextReader jsonReader = new JsonTextReader(clsidMapReader))
JsonDocument clsidMap;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be disposed.

using (Stream fileStream = File.OpenRead(clsidMapPath))
{
clsidMap = JObject.Load(jsonReader);
clsidMap = JsonDocument.Parse(clsidMapPath);
}

foreach (JProperty property in clsidMap.Properties())
foreach (var clsid in clsidMap.RootElement.EnumerateObject())
{
string guid = property.Name;
fileElement.Add(new XElement(ns + "comClass", new XAttribute("clsid", guid), new XAttribute("threadingModel", "Both")));
fileElement.Add(new XElement(ns + "comClass", new XAttribute("clsid", clsid.Name), new XAttribute("threadingModel", "Both")));
}

manifest.Add(fileElement);
Expand Down