Skip to content

Commit c6e1bd1

Browse files
committed
implement net7 support - references #4119
1 parent b2a9be1 commit c6e1bd1

File tree

4 files changed

+137
-1
lines changed

4 files changed

+137
-1
lines changed

src/Paket.Core/Versioning/FrameworkHandling.fs

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,30 @@ type Net6WindowsVersion =
103103
| "10.0.19041.0" | "10.0.19041" -> Some Net6WindowsVersion.V10_0_19041_0
104104
| _ -> None
105105

106+
[<RequireQualifiedAccess>]
107+
type Net7WindowsVersion =
108+
| V7_0
109+
| V8_0
110+
| V10_0_17763_0
111+
| V10_0_18362_0
112+
| V10_0_19041_0
113+
override this.ToString() =
114+
match this with
115+
| V7_0 -> "7.0"
116+
| V8_0 -> "8.0"
117+
| V10_0_17763_0 -> "10.0.17763.0"
118+
| V10_0_18362_0 -> "10.0.18362.0"
119+
| V10_0_19041_0 -> "10.0.19041.0"
120+
121+
static member TryParse s =
122+
match s with
123+
| "" | "7.0" | "7" -> Some Net7WindowsVersion.V7_0
124+
| "8.0" | "8" -> Some Net7WindowsVersion.V8_0
125+
| "10.0.17763.0" | "10.0.17763" -> Some Net7WindowsVersion.V10_0_17763_0
126+
| "10.0.18362.0" | "10.0.18362" -> Some Net7WindowsVersion.V10_0_18362_0
127+
| "10.0.19041.0" | "10.0.19041" -> Some Net7WindowsVersion.V10_0_19041_0
128+
| _ -> None
129+
106130
[<RequireQualifiedAccess>]
107131
type Net5Os =
108132
| Android
@@ -152,7 +176,31 @@ type Net6Os =
152176
] |> Seq.tryFind(fun (k,_) -> s.StartsWith k)
153177
|> Option.map snd
154178

155-
179+
[<RequireQualifiedAccess>]
180+
type Net7Os =
181+
| Android
182+
| IOs
183+
| MacOs
184+
| TvOs
185+
| WatchOs
186+
override this.ToString() =
187+
match this with
188+
| Android -> "android"
189+
| IOs -> "ios"
190+
| MacOs -> "macos"
191+
| TvOs -> "tvos"
192+
| WatchOs -> "watchos"
193+
194+
static member TryParse (s:string) =
195+
[
196+
("android",Net6Os.Android)
197+
("ios",Net6Os.IOs)
198+
("macos",Net6Os.MacOs)
199+
("tvos",Net6Os.TvOs)
200+
("watchos",Net6Os.WatchOs)
201+
] |> Seq.tryFind(fun (k,_) -> s.StartsWith k)
202+
|> Option.map snd
203+
156204

157205
[<RequireQualifiedAccess>]
158206
/// The Framework version.
@@ -179,6 +227,7 @@ type FrameworkVersion =
179227
| V4_8
180228
| V5
181229
| V6
230+
| V7
182231
override this.ToString() =
183232
match this with
184233
| V1 -> "v1.0"
@@ -202,6 +251,7 @@ type FrameworkVersion =
202251
| V4_8 -> "v4.8"
203252
| V5 -> "v5.0"
204253
| V6 -> "v6.0"
254+
| V7 -> "v7.0"
205255

206256
member this.ShortString() =
207257
match this with
@@ -226,6 +276,7 @@ type FrameworkVersion =
226276
| FrameworkVersion.V4_8 -> "48"
227277
| FrameworkVersion.V5 -> "5.0"
228278
| FrameworkVersion.V6 -> "6.0"
279+
| FrameworkVersion.V7 -> "7.0"
229280

230281
static member TryParse s =
231282
match s with
@@ -250,6 +301,7 @@ type FrameworkVersion =
250301
| "4.8" -> Some FrameworkVersion.V4_8
251302
| "5" -> Some FrameworkVersion.V5
252303
| "6" -> Some FrameworkVersion.V6
304+
| "7" -> Some FrameworkVersion.V7
253305
| _ -> None
254306

255307
[<RequireQualifiedAccess>]
@@ -683,6 +735,8 @@ type FrameworkIdentifier =
683735
| DotNetFramework of FrameworkVersion
684736
| DotNet6WithOs of Net6Os
685737
| DotNet6Windows of Net6WindowsVersion
738+
| DotNet7WithOs of Net7Os
739+
| DotNet7Windows of Net7WindowsVersion
686740
| DotNet5WithOs of Net5Os
687741
| DotNet5Windows of Net5WindowsVersion
688742
| UAP of UAPVersion
@@ -708,6 +762,8 @@ type FrameworkIdentifier =
708762
override x.ToString() =
709763
match x with
710764
| DotNetFramework v -> "net" + v.ShortString()
765+
| DotNet7WithOs o -> "net7.0-" + o.ToString()
766+
| DotNet7Windows v -> "net7.0-windows" + v.ToString()
711767
| DotNet6WithOs o -> "net6.0-" + o.ToString()
712768
| DotNet6Windows v -> "net6.0-windows" + v.ToString()
713769
| DotNet5WithOs o -> "net5.0-" + o.ToString()
@@ -813,6 +869,7 @@ type FrameworkIdentifier =
813869
| DotNetFramework FrameworkVersion.V4_8 -> [ DotNetFramework FrameworkVersion.V4_7_2 ]
814870
| DotNetFramework FrameworkVersion.V5 -> [ DotNetCoreApp DotNetCoreAppVersion.V3_1; DotNetStandard DotNetStandardVersion.V2_1 ]
815871
| DotNetFramework FrameworkVersion.V6 -> [ DotNetFramework FrameworkVersion.V5 ]
872+
| DotNetFramework FrameworkVersion.V7 -> [ DotNetFramework FrameworkVersion.V6 ]
816873
| DotNet5WithOs Net5Os.Android -> [ DotNetFramework FrameworkVersion.V5; MonoAndroid MonoAndroidVersion.V12 ]
817874
| DotNet5WithOs Net5Os.IOs -> [ DotNetFramework FrameworkVersion.V5; XamariniOS ]
818875
| DotNet5WithOs Net5Os.MacOs -> [ DotNetFramework FrameworkVersion.V5; XamarinMac ]
@@ -828,11 +885,21 @@ type FrameworkIdentifier =
828885
| DotNet6WithOs Net6Os.MacOs -> [ DotNetFramework FrameworkVersion.V6; XamarinMac ]
829886
| DotNet6WithOs Net6Os.TvOs -> [ DotNetFramework FrameworkVersion.V6; XamarinTV ]
830887
| DotNet6WithOs Net6Os.WatchOs -> [ DotNetFramework FrameworkVersion.V6; XamarinWatch ]
888+
| DotNet7WithOs Net7Os.Android -> [ DotNetFramework FrameworkVersion.V7; MonoAndroid MonoAndroidVersion.V12 ]
889+
| DotNet7WithOs Net7Os.IOs -> [ DotNetFramework FrameworkVersion.V7; XamariniOS ]
890+
| DotNet7WithOs Net7Os.MacOs -> [ DotNetFramework FrameworkVersion.V7; XamarinMac ]
891+
| DotNet7WithOs Net7Os.TvOs -> [ DotNetFramework FrameworkVersion.V7; XamarinTV ]
892+
| DotNet7WithOs Net7Os.WatchOs -> [ DotNetFramework FrameworkVersion.V7; XamarinWatch ]
831893
| DotNet6Windows Net6WindowsVersion.V7_0 -> [ DotNetFramework FrameworkVersion.V6 ]
832894
| DotNet6Windows Net6WindowsVersion.V8_0 -> [ DotNetFramework FrameworkVersion.V6; DotNet6Windows Net6WindowsVersion.V7_0 ]
833895
| DotNet6Windows Net6WindowsVersion.V10_0_17763_0 -> [ DotNetFramework FrameworkVersion.V6; DotNet6Windows Net6WindowsVersion.V8_0 ]
834896
| DotNet6Windows Net6WindowsVersion.V10_0_18362_0 -> [ DotNetFramework FrameworkVersion.V6; DotNet6Windows Net6WindowsVersion.V10_0_17763_0 ]
835897
| DotNet6Windows Net6WindowsVersion.V10_0_19041_0 -> [ DotNetFramework FrameworkVersion.V6; DotNet6Windows Net6WindowsVersion.V10_0_18362_0 ]
898+
| DotNet7Windows Net7WindowsVersion.V7_0 -> [ DotNetFramework FrameworkVersion.V7 ]
899+
| DotNet7Windows Net7WindowsVersion.V8_0 -> [ DotNetFramework FrameworkVersion.V7; DotNet7Windows Net7WindowsVersion.V7_0 ]
900+
| DotNet7Windows Net7WindowsVersion.V10_0_17763_0 -> [ DotNetFramework FrameworkVersion.V7; DotNet7Windows Net7WindowsVersion.V8_0 ]
901+
| DotNet7Windows Net7WindowsVersion.V10_0_18362_0 -> [ DotNetFramework FrameworkVersion.V7; DotNet7Windows Net7WindowsVersion.V10_0_17763_0 ]
902+
| DotNet7Windows Net7WindowsVersion.V10_0_19041_0 -> [ DotNetFramework FrameworkVersion.V7; DotNet7Windows Net7WindowsVersion.V10_0_18362_0 ]
836903
| DotNetStandard DotNetStandardVersion.V1_0 -> [ ]
837904
| DotNetStandard DotNetStandardVersion.V1_1 -> [ DotNetStandard DotNetStandardVersion.V1_0 ]
838905
| DotNetStandard DotNetStandardVersion.V1_2 -> [ DotNetStandard DotNetStandardVersion.V1_1 ]
@@ -946,6 +1013,7 @@ module FrameworkDetection =
9461013
|> function
9471014
| Some "5" when dotnetVersionX = 5 -> tryParseSecondPart parts.[1]
9481015
| Some "6" when dotnetVersionX = 6 -> tryParseSecondPart parts.[1]
1016+
| Some "7" when dotnetVersionX = 7 -> tryParseSecondPart parts.[1]
9491017
| _ -> None
9501018
else
9511019
None
@@ -958,6 +1026,7 @@ module FrameworkDetection =
9581026
|> function
9591027
| Some "5" when dotnetVersionX = 5 -> tryParseVersion winVersionPart
9601028
| Some "6" when dotnetVersionX = 6 -> tryParseVersion winVersionPart
1029+
| Some "7" when dotnetVersionX = 7 -> tryParseVersion winVersionPart
9611030
| _ -> None
9621031
else
9631032
None
@@ -1378,6 +1447,7 @@ module KnownTargetProfiles =
13781447
FrameworkVersion.V4_8
13791448
FrameworkVersion.V5
13801449
FrameworkVersion.V6
1450+
FrameworkVersion.V7
13811451
]
13821452

13831453
let DotNetFrameworkIdentifiers =
@@ -1436,6 +1506,30 @@ module KnownTargetProfiles =
14361506
DotNet6WindowsVersions
14371507
|> List.map (DotNet6Windows >> TargetProfile.SinglePlatform)
14381508

1509+
let DotNet7OperatingSystems = [
1510+
Net7Os.Android
1511+
Net7Os.IOs
1512+
Net7Os.MacOs
1513+
Net7Os.TvOs
1514+
Net7Os.WatchOs
1515+
]
1516+
1517+
let DotNet7WithOsProfiles =
1518+
DotNet7OperatingSystems
1519+
|> List.map (DotNet7WithOs >> TargetProfile.SinglePlatform)
1520+
1521+
let DotNet7WindowsVersions = [
1522+
Net7WindowsVersion.V7_0
1523+
Net7WindowsVersion.V8_0
1524+
Net7WindowsVersion.V10_0_17763_0
1525+
Net7WindowsVersion.V10_0_18362_0
1526+
Net7WindowsVersion.V10_0_19041_0
1527+
]
1528+
1529+
let DotNet7WindowsProfiles =
1530+
DotNet7WindowsVersions
1531+
|> List.map (DotNet7Windows >> TargetProfile.SinglePlatform)
1532+
14391533
let DotNetStandardVersions = [
14401534
DotNetStandardVersion.V1_0
14411535
DotNetStandardVersion.V1_1
@@ -1607,6 +1701,8 @@ module KnownTargetProfiles =
16071701

16081702
let AllDotNetProfiles =
16091703
DotNetFrameworkProfiles @
1704+
DotNet7WithOsProfiles @
1705+
DotNet7WindowsProfiles @
16101706
DotNet6WithOsProfiles @
16111707
DotNet6WindowsProfiles @
16121708
DotNet5WithOsProfiles @

src/Paket.Core/Versioning/PlatformMatching.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ let getTargetCondition (target:TargetProfile) =
213213
match target with
214214
| TargetProfile.SinglePlatform(platform) ->
215215
match platform with
216+
| DotNetFramework(FrameworkVersion.V7) ->"$(TargetFrameworkIdentifier) == '.NETCoreApp'", "$(TargetFrameworkVersion) == 'v7.0'"
216217
| DotNetFramework(FrameworkVersion.V6) ->"$(TargetFrameworkIdentifier) == '.NETCoreApp'", "$(TargetFrameworkVersion) == 'v6.0'"
217218
| DotNetFramework(FrameworkVersion.V5) ->"$(TargetFrameworkIdentifier) == '.NETCoreApp'", "$(TargetFrameworkVersion) == 'v5.0'"
218219
| DotNetFramework(version) ->"$(TargetFrameworkIdentifier) == '.NETFramework'", sprintf "$(TargetFrameworkVersion) == '%O'" version

tests/Paket.Tests/DependenciesFile/ParserSpecs.fs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,21 @@ let ``should read config with .NET 6 target framework``() =
12281228
|> getExplicitRestriction
12291229
|> shouldEqual (FrameworkRestriction.AtLeast(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V6)))
12301230

1231+
let configNET7TargetFramework = """source https://www.nuget.org/api/v2
1232+
1233+
framework: >= net7.0
1234+
1235+
nuget System.Data.SQLite 1.0.98.1 content: none
1236+
"""
1237+
1238+
[<Test>]
1239+
let ``should read config with .NET 7 target framework``() =
1240+
let cfg = DependenciesFile.FromSource(configNET7TargetFramework)
1241+
1242+
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.FrameworkRestrictions
1243+
|> getExplicitRestriction
1244+
|> shouldEqual (FrameworkRestriction.AtLeast(FrameworkIdentifier.DotNetFramework(FrameworkVersion.V7)))
1245+
12311246
let validFrameworks =
12321247
let net40 = DotNetFramework(FrameworkVersion.V4)
12331248
let net45 = DotNetFramework(FrameworkVersion.V4_5)

tests/Paket.Tests/Versioning/PlatformMatchingSpecs.fs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,30 @@ let ``Can detect a bunch of net6 platforms``() =
232232
if not (List.isEmpty errors) then
233233
failwith (String.concat "\n" errors)
234234

235+
[<Test>]
236+
let ``Can detect a bunch of net7 platforms``() =
237+
let testSet = [
238+
"net7" , TargetProfile.SinglePlatform (FrameworkIdentifier.DotNetFramework FrameworkVersion.V7)
239+
"net7000" , TargetProfile.SinglePlatform (FrameworkIdentifier.DotNetFramework FrameworkVersion.V7)
240+
"net7.0-windows" , TargetProfile.SinglePlatform (FrameworkIdentifier.DotNet7Windows Net7WindowsVersion.V7_0)
241+
"net7-windows" , TargetProfile.SinglePlatform (FrameworkIdentifier.DotNet7Windows Net7WindowsVersion.V7_0)
242+
"net7.0-windows10.0.19041.0" , TargetProfile.SinglePlatform (FrameworkIdentifier.DotNet7Windows Net7WindowsVersion.V10_0_19041_0)
243+
"net7.0-windows10.0.19041" , TargetProfile.SinglePlatform (FrameworkIdentifier.DotNet7Windows Net7WindowsVersion.V10_0_19041_0)
244+
"net7-windows10.0.19041" , TargetProfile.SinglePlatform (FrameworkIdentifier.DotNet7Windows Net7WindowsVersion.V10_0_19041_0)
245+
"net7000-windows10.0.19041" , TargetProfile.SinglePlatform (FrameworkIdentifier.DotNet7Windows Net7WindowsVersion.V10_0_19041_0)
246+
"net7.0-android30.0" , TargetProfile.SinglePlatform (FrameworkIdentifier.DotNet7WithOs Net7Os.Android)
247+
]
248+
249+
let errors = [
250+
for p, expected in testSet do
251+
let parsed = (PlatformMatching.forceExtractPlatforms p).ToTargetProfile false
252+
if parsed <> Some expected then
253+
sprintf "%s resulted into %A instead of %A" p parsed expected
254+
]
255+
256+
if not (List.isEmpty errors) then
257+
failwith (String.concat "\n" errors)
258+
235259
[<Test>]
236260
let ``Can detect netstandard1.6``() =
237261
let p = PlatformMatching.forceExtractPlatforms "netstandard1.6"

0 commit comments

Comments
 (0)