Skip to content

Commit 188c122

Browse files
authored
Resolve JSON.Net version and next major version from Nest.csproj (#2865)
Resolve JSON.Net version and major version from <project>.csproj
1 parent fa4c67b commit 188c122

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
@@ -8,7 +8,10 @@
88
#load @"Versioning.fsx"
99

1010
open System
11+
open System.IO
12+
open System.Linq
1113
open System.Text
14+
open System.Xml.Linq
1215
open Microsoft.FSharp.Quotations
1316
open Microsoft.FSharp.Quotations.Patterns
1417
open Fake
@@ -34,10 +37,22 @@ module Release =
3437

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

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

4257
let properties =
4358
let addKeyValue (e:Expr<string>) (builder:StringBuilder) =
@@ -48,7 +63,9 @@ module Release =
4863
| PropertyGet (eo, pi, li) -> (pi.Name, (pi.GetValue(e) |> string))
4964
| ValueWithName (obj,ty,nm) -> ((obj |> string), nm)
5065
| _ -> failwith (sprintf "%A is not a let-bound value. %A" e (e.GetType()))
51-
builder.AppendFormat("{0}=\"{1}\";", key, value);
66+
67+
if (isNotNullOrEmpty value) then builder.AppendFormat("{0}=\"{1}\";", key, value)
68+
else builder
5269
new StringBuilder()
5370
|> addKeyValue <@nextMajorVersion@>
5471
|> addKeyValue <@year@>
@@ -73,4 +90,4 @@ module Release =
7390
match success with
7491
| 0 -> traceFAKE "publish to myget succeeded" |> ignore
7592
| _ -> failwith "publish to myget failed" |> ignore
76-
)
93+
)

0 commit comments

Comments
 (0)