From 730eacc6b119f24105abab53fcdd4426430c19a1 Mon Sep 17 00:00:00 2001 From: Andrii Chebukin Date: Mon, 7 Aug 2023 20:11:13 +0400 Subject: [PATCH] Fixed `NullReferenceException` on missing `version` in `global.json` --- src/app/Fake.DotNet.Cli/DotNet.fs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/app/Fake.DotNet.Cli/DotNet.fs b/src/app/Fake.DotNet.Cli/DotNet.fs index c1bf41ec76c..2503fe4c176 100644 --- a/src/app/Fake.DotNet.Cli/DotNet.fs +++ b/src/app/Fake.DotNet.Cli/DotNet.fs @@ -66,8 +66,12 @@ module DotNet = let content = File.ReadAllText globalJson.FullName let json = JObject.Parse content let sdk = json.Item("sdk") :?> JObject - let version = sdk.Property("version").Value.ToString() - Some version + match sdk.Property("version") with + | null -> None + | version -> + let versionValue = version.Value.ToString() + let _ = Version.Parse (versionValue) + Some versionValue with exn -> failwithf "Could not parse `sdk.version` from global.json at '%s': %s" globalJson.FullName exn.Message