88#load @" Versioning.fsx"
99
1010open System
11+ open System.IO
12+ open System.Linq
1113open System.Text
14+ open System.Xml .Linq
1215open Microsoft.FSharp .Quotations
1316open Microsoft.FSharp .Quotations .Patterns
1417open 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