From 00e887e350688bee473448cd5751695155723a7a Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Sun, 6 Oct 2024 10:29:56 +0100 Subject: [PATCH] Change the global.json parsing in Fake.Dotnet.Cli to use System.Text.Json instead of Newtonsoft.Json --- src/app/Fake.DotNet.Cli/DotNet.fs | 15 +++++++++------ src/app/Fake.DotNet.Cli/paket.references | 1 - 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/app/Fake.DotNet.Cli/DotNet.fs b/src/app/Fake.DotNet.Cli/DotNet.fs index f9663feea5a..98f0ab4e668 100644 --- a/src/app/Fake.DotNet.Cli/DotNet.fs +++ b/src/app/Fake.DotNet.Cli/DotNet.fs @@ -17,7 +17,7 @@ module DotNet = open System.IO open System.Security.Cryptography open System.Text - open Newtonsoft.Json.Linq + open System.Text.Json /// /// .NET Core SDK default install directory (set to default SDK installer paths @@ -64,12 +64,15 @@ module DotNet = | Some globalJson -> try let content = File.ReadAllText globalJson.FullName - let json = JObject.Parse content - let sdk = json.Item("sdk") :?> JObject - match sdk.Property("version") with - | null -> None - | version -> Some(version.Value.ToString()) + let json = + JsonDocument.Parse(content, JsonDocumentOptions(CommentHandling = JsonCommentHandling.Skip)) + + let sdk = json.RootElement.GetProperty("sdk") + + match sdk.TryGetProperty("version") with + | false, _ -> None + | true, version -> Some(version.GetString()) with exn -> failwithf "Could not parse `sdk.version` from global.json at '%s': %s" globalJson.FullName exn.Message diff --git a/src/app/Fake.DotNet.Cli/paket.references b/src/app/Fake.DotNet.Cli/paket.references index b49312fb335..5c07540f500 100644 --- a/src/app/Fake.DotNet.Cli/paket.references +++ b/src/app/Fake.DotNet.Cli/paket.references @@ -2,6 +2,5 @@ group fakemodule FSharp.Core NETStandard.Library -Newtonsoft.Json // https://stackoverflow.com/questions/58326739/how-can-i-find-the-target-of-a-linux-symlink-in-c-sharp Mono.Posix.NETStandard