Skip to content

Commit

Permalink
Change the global.json parsing in Fake.Dotnet.Cli to use System.Text.…
Browse files Browse the repository at this point in the history
…Json instead of Newtonsoft.Json
  • Loading branch information
Numpsy committed Oct 6, 2024
1 parent 6f2fc43 commit 51fd9d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
15 changes: 9 additions & 6 deletions src/app/Fake.DotNet.Cli/DotNet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module DotNet =
open System.IO
open System.Security.Cryptography
open System.Text
open Newtonsoft.Json.Linq
open System.Text.Json

/// <summary>
/// .NET Core SDK default install directory (set to default SDK installer paths
Expand Down Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion src/app/Fake.DotNet.Cli/paket.references
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 51fd9d8

Please sign in to comment.