Skip to content

Commit 92f2baa

Browse files
committed
Resolve JSON.Net version and next major version from Nest.csproj (#2865)
Resolve JSON.Net version and major version from <project>.csproj (cherry picked from commit 188c122)
1 parent 1e60af2 commit 92f2baa

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

build/scripts/Paths.fsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ module Paths =
3434
let Output(folder) = sprintf "%s/%s" BuildOutput folder
3535
let Source(folder) = sprintf "%s/%s" SourceFolder folder
3636
let Build(folder) = sprintf "%s/%s" BuildFolder folder
37+
38+
let ProjFile(project:DotNetProject) =
39+
match project with
40+
| Project p -> sprintf "%s/%s/%s.csproj" SourceFolder project.Name project.Name
41+
| PrivateProject p ->
42+
match p with
43+
| Tests -> sprintf "%s/%s/%s.csproj" SourceFolder project.Name project.Name
44+
| DocGenerator -> sprintf "%s/CodeGeneration/%s/%s.csproj" SourceFolder project.Name project.Name
45+
3746

3847
let BinFolder(folder) =
3948
let f = replace @"\" "/" folder

build/scripts/Releasing.fsx

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
#load @"Versioning.fsx"
88

99
open System
10+
open System.IO
11+
open System.Linq
1012
open System.Text
13+
open System.Xml.Linq
1114
open Microsoft.FSharp.Quotations
1215
open Microsoft.FSharp.Quotations.Patterns
1316
open Fake
@@ -33,10 +36,22 @@ module Release =
3336

3437
let year = sprintf "%i" DateTime.UtcNow.Year
3538

36-
let jsonDotNetVersion = 10
37-
38-
let jsonDotNetCurrentVersion = sprintf "%i" jsonDotNetVersion
39-
let jsonDotNetNextVersion = sprintf "%i" (jsonDotNetVersion + 1)
39+
let jsonDotNetCurrentVersion =
40+
let xName n = XName.op_Implicit n
41+
use stream = File.OpenRead <| Paths.ProjFile p
42+
let doc = XDocument.Load(stream)
43+
let packageReference =
44+
doc.Descendants(xName "PackageReference")
45+
.FirstOrDefault(fun e -> e.Attribute(xName "Include").Value = "Newtonsoft.Json")
46+
if (packageReference <> null) then packageReference.Attribute(xName "Version").Value
47+
else String.Empty
48+
49+
let jsonDotNetNextVersion =
50+
match jsonDotNetCurrentVersion with
51+
| "" -> String.Empty
52+
| version ->
53+
let semanticVersion = SemVerHelper.parse version
54+
sprintf "%i" (semanticVersion.Major + 1)
4055

4156
let properties =
4257
let addKeyValue (e:Expr<string>) (builder:StringBuilder) =
@@ -47,7 +62,9 @@ module Release =
4762
| PropertyGet (eo, pi, li) -> (pi.Name, (pi.GetValue(e) |> string))
4863
| ValueWithName (obj,ty,nm) -> ((obj |> string), nm)
4964
| _ -> failwith (sprintf "%A is not a let-bound value. %A" e (e.GetType()))
50-
builder.AppendFormat("{0}=\"{1}\";", key, value);
65+
66+
if (isNotNullOrEmpty value) then builder.AppendFormat("{0}=\"{1}\";", key, value)
67+
else builder
5168
new StringBuilder()
5269
|> addKeyValue <@nextMajorVersion@>
5370
|> addKeyValue <@year@>
@@ -72,4 +89,4 @@ module Release =
7289
match success with
7390
| 0 -> traceFAKE "publish to myget succeeded" |> ignore
7491
| _ -> failwith "publish to myget failed" |> ignore
75-
)
92+
)

0 commit comments

Comments
 (0)