77#load @" Versioning.fsx"
88
99open System
10+ open System.IO
11+ open System.Linq
1012open System.Text
13+ open System.Xml .Linq
1114open Microsoft.FSharp .Quotations
1215open Microsoft.FSharp .Quotations .Patterns
1316open 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