Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target framework matching improvements for .NET 5.0 #3938

Merged
merged 3 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 59 additions & 40 deletions src/Paket.Core/Versioning/FrameworkHandling.fs
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ type Net5WindowsVersion =

static member TryParse s =
match s with
| "7.0" -> Some Net5WindowsVersion.V7_0
| "8.0" -> Some Net5WindowsVersion.V8_0
| "10.0.17763.0" -> Some Net5WindowsVersion.V10_0_17763_0
| "10.0.18362.0" -> Some Net5WindowsVersion.V10_0_18362_0
| "10.0.19041.0" -> Some Net5WindowsVersion.V10_0_19041_0
| "" | "7.0" | "7" -> Some Net5WindowsVersion.V7_0
| "8.0" | "8" -> Some Net5WindowsVersion.V8_0
| "10.0.17763.0" | "10.0.17763" -> Some Net5WindowsVersion.V10_0_17763_0
| "10.0.18362.0" | "10.0.18362" -> Some Net5WindowsVersion.V10_0_18362_0
| "10.0.19041.0" | "10.0.19041" -> Some Net5WindowsVersion.V10_0_19041_0
| _ -> None

[<RequireQualifiedAccess>]
Expand All @@ -86,30 +86,21 @@ type Net5Os =
| MacOs
| TvOs
| WatchOs
| Windows
| WindowsWithVersion of Net5WindowsVersion
override this.ToString() =
match this with
| Android -> "android"
| IOs -> "ios"
| MacOs -> "macos"
| TvOs -> "tvos"
| WatchOs -> "watchos"
| Windows -> "windows"
| WindowsWithVersion v -> "windows" + v.ToString()

static member TryParse s =
match s with
| "android" -> Some Net5Os.Android
| "ios" -> Some Net5Os.Android
| "macos" -> Some Net5Os.Android
| "tvos" -> Some Net5Os.Android
| "watchos" -> Some Net5Os.Android
| "windows" -> Some Net5Os.Android
| _ when s.StartsWith("windows") ->
let versionPart = s.Substring ("windows".Length)
Net5WindowsVersion.TryParse(versionPart)
|> Option.map Net5Os.WindowsWithVersion
| "ios" -> Some Net5Os.IOs
| "macos" -> Some Net5Os.MacOs
| "tvos" -> Some Net5Os.TvOs
| "watchos" -> Some Net5Os.WatchOs
| _ -> None

[<RequireQualifiedAccess>]
Expand All @@ -136,7 +127,6 @@ type FrameworkVersion =
| V4_7_2
| V4_8
| V5
| V5WithOs of Net5Os
override this.ToString() =
match this with
| V1 -> "v1.0"
Expand All @@ -159,7 +149,6 @@ type FrameworkVersion =
| V4_7_2 -> "v4.7.2"
| V4_8 -> "v4.8"
| V5 -> "v5.0"
| V5WithOs o-> "v5.0-" + o.ToString()

member this.ShortString() =
match this with
Expand All @@ -182,8 +171,7 @@ type FrameworkVersion =
| FrameworkVersion.V4_7_1 -> "471"
| FrameworkVersion.V4_7_2 -> "472"
| FrameworkVersion.V4_8 -> "48"
| FrameworkVersion.V5 -> "5.0"
| FrameworkVersion.V5WithOs o -> "5.0-" + o.ToString()
| FrameworkVersion.V5 -> "50"

static member TryParse s =
match s with
Expand All @@ -206,11 +194,7 @@ type FrameworkVersion =
| "4.7.1" -> Some FrameworkVersion.V4_7_1
| "4.7.2" -> Some FrameworkVersion.V4_7_2
| "4.8" -> Some FrameworkVersion.V4_8
| "5.0" | "5" -> Some FrameworkVersion.V5
| _ when s.StartsWith("5.0") ->
let osPart = s.Substring ("5.0".Length)
Net5Os.TryParse(osPart)
|> Option.map FrameworkVersion.V5WithOs
| "5" -> Some FrameworkVersion.V5
| _ -> None

[<RequireQualifiedAccess>]
Expand Down Expand Up @@ -627,6 +611,8 @@ type TizenVersion =
// Each time a new version is added NuGetPackageCache.CurrentCacheVersion should be bumped.
type FrameworkIdentifier =
| DotNetFramework of FrameworkVersion
| DotNet5WithOs of Net5Os
| DotNet5Windows of Net5WindowsVersion
| UAP of UAPVersion
| DotNetStandard of DotNetStandardVersion
| DotNetCoreApp of DotNetCoreAppVersion
Expand All @@ -650,6 +636,8 @@ type FrameworkIdentifier =
override x.ToString() =
match x with
| DotNetFramework v -> "net" + v.ShortString()
| DotNet5WithOs o -> "net5.0-" + o.ToString()
| DotNet5Windows v -> "net5.0-windows" + v.ToString()
| DotNetStandard v -> "netstandard" + v.ShortString()
| DotNetCoreApp v -> "netcoreapp" + v.ShortString()
| DotNetUnity v -> "net" + v.ShortString()
Expand Down Expand Up @@ -747,8 +735,16 @@ type FrameworkIdentifier =
| DotNetFramework FrameworkVersion.V4_7_2 -> [ DotNetFramework FrameworkVersion.V4_7_1 ]
| DotNetFramework FrameworkVersion.V4_8 -> [ DotNetFramework FrameworkVersion.V4_7_2 ]
| DotNetFramework FrameworkVersion.V5 -> [ DotNetCoreApp DotNetCoreAppVersion.V3_1; DotNetStandard DotNetStandardVersion.V2_1 ]
| DotNetFramework (FrameworkVersion.V5WithOs(Net5Os.WindowsWithVersion(_))) -> [ DotNetFramework (FrameworkVersion.V5WithOs(Net5Os.Windows)) ]
| DotNetFramework (FrameworkVersion.V5WithOs(_)) -> [ DotNetFramework FrameworkVersion.V5 ]
| DotNet5WithOs Net5Os.Android -> [ DotNetFramework FrameworkVersion.V5; MonoAndroid MonoAndroidVersion.V10 ]
| DotNet5WithOs Net5Os.IOs -> [ DotNetFramework FrameworkVersion.V5; XamariniOS ]
| DotNet5WithOs Net5Os.MacOs -> [ DotNetFramework FrameworkVersion.V5; XamarinMac ]
| DotNet5WithOs Net5Os.TvOs -> [ DotNetFramework FrameworkVersion.V5; XamarinTV ]
| DotNet5WithOs Net5Os.WatchOs -> [ DotNetFramework FrameworkVersion.V5; XamarinWatch ]
| DotNet5Windows Net5WindowsVersion.V7_0 -> [ DotNetFramework FrameworkVersion.V5 ]
| DotNet5Windows Net5WindowsVersion.V8_0 -> [ DotNetFramework FrameworkVersion.V5; DotNet5Windows Net5WindowsVersion.V7_0 ]
| DotNet5Windows Net5WindowsVersion.V10_0_17763_0 -> [ DotNetFramework FrameworkVersion.V5; DotNet5Windows Net5WindowsVersion.V8_0 ]
| DotNet5Windows Net5WindowsVersion.V10_0_18362_0 -> [ DotNetFramework FrameworkVersion.V5; DotNet5Windows Net5WindowsVersion.V10_0_17763_0 ]
| DotNet5Windows Net5WindowsVersion.V10_0_19041_0 -> [ DotNetFramework FrameworkVersion.V5; DotNet5Windows Net5WindowsVersion.V10_0_18362_0 ]
| DotNetStandard DotNetStandardVersion.V1_0 -> [ ]
| DotNetStandard DotNetStandardVersion.V1_1 -> [ DotNetStandard DotNetStandardVersion.V1_0 ]
| DotNetStandard DotNetStandardVersion.V1_2 -> [ DotNetStandard DotNetStandardVersion.V1_1 ]
Expand Down Expand Up @@ -847,6 +843,12 @@ module FrameworkDetection =
Some (v.ToString() |> simplify)
else None

let (|MatchTfmString|_|) (tfmStart: string) tryParseSecondPart (s:string) =
if s.StartsWith tfmStart then
let secondPart = s.Substring (tfmStart.Length)
tryParseSecondPart secondPart
else
None
let (|MatchTfm|_|) (tfmStart: string) tryParseVersion (s:string) =
if s.StartsWith tfmStart then
let versionPart = s.Substring (tfmStart.Length)
Expand Down Expand Up @@ -895,6 +897,8 @@ module FrameworkDetection =
| "net35-Unity Micro v3.5" -> Some (DotNetUnity DotNetUnityVersion.V3_5_Micro)
| "net35-Unity Subset v3.5" -> Some (DotNetUnity DotNetUnityVersion.V3_5_Subset)
| "net35-Unity Full v3.5" -> Some (DotNetUnity DotNetUnityVersion.V3_5_Full)
| MatchTfm "net5.0-win" Net5WindowsVersion.TryParse fm -> Some (DotNet5Windows fm)
| MatchTfmString "net5.0-" Net5Os.TryParse fm -> Some (DotNet5WithOs fm)
| ModifyMatchTfm skipFullAndClient "net" FrameworkVersion.TryParse fm -> Some (DotNetFramework fm)
// Backwards compat quirk (2017-08-20).
| "uap101" -> Some (UAP UAPVersion.V10_1)
Expand Down Expand Up @@ -1262,17 +1266,6 @@ module KnownTargetProfiles =
FrameworkVersion.V4_7_2
FrameworkVersion.V4_8
FrameworkVersion.V5
FrameworkVersion.V5WithOs(Net5Os.Android)
FrameworkVersion.V5WithOs(Net5Os.IOs)
FrameworkVersion.V5WithOs(Net5Os.MacOs)
FrameworkVersion.V5WithOs(Net5Os.TvOs)
FrameworkVersion.V5WithOs(Net5Os.WatchOs)
FrameworkVersion.V5WithOs(Net5Os.Windows)
FrameworkVersion.V5WithOs(Net5Os.WindowsWithVersion(Net5WindowsVersion.V7_0))
FrameworkVersion.V5WithOs(Net5Os.WindowsWithVersion(Net5WindowsVersion.V8_0))
FrameworkVersion.V5WithOs(Net5Os.WindowsWithVersion(Net5WindowsVersion.V10_0_17763_0))
FrameworkVersion.V5WithOs(Net5Os.WindowsWithVersion(Net5WindowsVersion.V10_0_18362_0))
FrameworkVersion.V5WithOs(Net5Os.WindowsWithVersion(Net5WindowsVersion.V10_0_19041_0))
]

let DotNetFrameworkIdentifiers =
Expand All @@ -1283,6 +1276,30 @@ module KnownTargetProfiles =
DotNetFrameworkIdentifiers
|> List.map TargetProfile.SinglePlatform

let DotNet5OperatingSystems = [
Net5Os.Android
Net5Os.IOs
Net5Os.MacOs
Net5Os.TvOs
Net5Os.WatchOs
]

let DotNet5WithOsProfiles =
DotNet5OperatingSystems
|> List.map (DotNet5WithOs >> TargetProfile.SinglePlatform)

let DotNet5WindowsVersions = [
Net5WindowsVersion.V7_0
Net5WindowsVersion.V8_0
Net5WindowsVersion.V10_0_17763_0
Net5WindowsVersion.V10_0_18362_0
Net5WindowsVersion.V10_0_19041_0
]

let DotNet5WindowsProfiles =
DotNet5WindowsVersions
|> List.map (DotNet5Windows >> TargetProfile.SinglePlatform)

let DotNetStandardVersions = [
DotNetStandardVersion.V1_0
DotNetStandardVersion.V1_1
Expand Down Expand Up @@ -1451,6 +1468,8 @@ module KnownTargetProfiles =

let AllDotNetProfiles =
DotNetFrameworkProfiles @
DotNet5WithOsProfiles @
DotNet5WindowsProfiles @
DotNetUnityProfiles @
WindowsProfiles @
WindowsPhoneAppProfiles @
Expand Down
4 changes: 4 additions & 0 deletions src/Paket.Core/Versioning/PlatformMatching.fs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,11 @@ let getTargetCondition (target:TargetProfile) =
match target with
| TargetProfile.SinglePlatform(platform) ->
match platform with
| DotNetFramework(FrameworkVersion.V5) ->"$(TargetFrameworkIdentifier) == '.NETCoreApp'", "$(TargetFrameworkVersion) == 'v5.0'"
| DotNetFramework(version) ->"$(TargetFrameworkIdentifier) == '.NETFramework'", sprintf "$(TargetFrameworkVersion) == '%O'" version
| DotNet5WithOs(os) ->"$(TargetFrameworkIdentifier) == '.NETCoreApp'", sprintf "($(TargetFrameworkVersion) == 'v5.0' And $(TargetPlatformIdentifier) == '%O')" os
| DotNet5Windows(Net5WindowsVersion.V7_0) ->"$(TargetFrameworkIdentifier) == '.NETCoreApp'", sprintf "($(TargetFrameworkVersion) == 'v5.0' And $(TargetPlatformIdentifier) == 'Windows')"
| DotNet5Windows(version) ->"$(TargetFrameworkIdentifier) == '.NETCoreApp'", sprintf "($(TargetFrameworkVersion) == 'v5.0' And $(TargetPlatformIdentifier) == 'Windows' And $(TargetPlatformVersion) == '%O')" version
| DotNetStandard(version) ->"$(TargetFrameworkIdentifier) == '.NETStandard'", sprintf "$(TargetFrameworkVersion) == '%O'" version
| DotNetCoreApp(version) ->"$(TargetFrameworkIdentifier) == '.NETCoreApp'", sprintf "$(TargetFrameworkVersion) == '%O'" version
| DotNetUnity(DotNetUnityVersion.V3_5_Full as version) ->
Expand Down
Loading