From 2019f915c1adb5ece6c144e7b57f79689eb16115 Mon Sep 17 00:00:00 2001 From: Marcio Rinaldi Date: Fri, 18 Sep 2015 18:02:28 -0300 Subject: [PATCH] Converts FrameworkName to FrameworkIdentifier --- src/Paket.Core/FrameworkHandling.fs | 88 ++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/src/Paket.Core/FrameworkHandling.fs b/src/Paket.Core/FrameworkHandling.fs index fd9ee2ca6d..7d0a9415ac 100644 --- a/src/Paket.Core/FrameworkHandling.fs +++ b/src/Paket.Core/FrameworkHandling.fs @@ -1,7 +1,8 @@ -namespace Paket +namespace Paket open System.IO open System +open System.Runtime.Versioning [] /// The Framework version. @@ -141,6 +142,91 @@ type FrameworkIdentifier = | WindowsPhoneApp _ -> [ WindowsPhoneApp "v8.1" ] | WindowsPhoneSilverlight _ -> [ WindowsPhoneSilverlight "v8.1" ] +module FrameworkConversion = + let version (input: FrameworkName) = + sprintf "v%O" input.Version + + let (|DotNetFramework|_|) (input: FrameworkName) = + match input.Identifier with + | ".NETFramework" -> Some (version input,input.Profile) + | _ -> None + let (|DNX|_|) (input: FrameworkName) = + match input.Identifier with + | "DNX" -> Some (version input) + | _ -> None + let (|DNXCore|_|) (input: FrameworkName) = + match input.Identifier with + | "DNXCore" -> Some (version input) + | _ -> None + let (|Windows|_|) (input: FrameworkName) = + match input.Identifier with + | ".NETCore" -> Some (version input) + | _ -> None + let (|Silverlight|_|) (input: FrameworkName) = + match input.Identifier with + | "Silverlight" -> Some (version input) + | _ -> None + let (|WindowsPhoneApp|_|) (input: FrameworkName) = + match input.Identifier with + | "WindowsPhoneApp" -> Some (version input) + | _ -> None + let (|WindowsPhoneSilverlight|_|) (input: FrameworkName) = + match input.Identifier with + | "WindowsPhone" -> Some (version input) + | _ -> None + let (|MonoAndroid|_|) (input: FrameworkName) = + match input.Identifier with + | "MonoAndroid" -> Some () + | _ -> None + let (|MonoTouch|_|) (input: FrameworkName) = + match input.Identifier with + | "MonoTouch" -> Some () + | _ -> None + let (|MonoMac|_|) (input: FrameworkName) = + match input.Identifier with + | "MonoMac" -> Some () + | _ -> None + let (|XamariniOS|_|) (input: FrameworkName) = + match input.Identifier with + | "Xamarin.iOS" -> Some () + | _ -> None + let (|XamarinMac|_|) (input: FrameworkName) = + match input.Identifier with + | "Xamarin.Mac" -> Some () + | _ -> None + + let convertToFrameworkIdentifier frameworkName = + let version v = + match v with + | "v1.0","" -> Some(FrameworkVersion.V1) + | "v1.1","" -> Some(FrameworkVersion.V1_1) + | "v2.0","" -> Some(FrameworkVersion.V2) + | "v3.0","" -> Some(FrameworkVersion.V3) + | "v3.5","" -> Some(FrameworkVersion.V3_5) + | "v4.0","" -> Some(FrameworkVersion.V4) + | "v4.0","Client" -> Some(FrameworkVersion.V4_Client) + | "v4.5","" -> Some(FrameworkVersion.V4_5) + | "v4.5.1","" -> Some(FrameworkVersion.V4_5_1) + | "v4.5.2","" -> Some(FrameworkVersion.V4_5_2) + | "v4.5.3","" -> Some(FrameworkVersion.V4_5_3) + | "v4.6","" -> Some(FrameworkVersion.V4_6) + | "v5.0","" -> Some(FrameworkVersion.V5_0) + | _ -> None + + match frameworkName with + | DotNetFramework v -> version v |> Option.map FrameworkIdentifier.DotNetFramework + | DNX v -> version (v,null) |> Option.map FrameworkIdentifier.DNX + | DNXCore v -> version (v,null) |> Option.map FrameworkIdentifier.DNXCore + | Windows v -> FrameworkIdentifier.Windows(v) |> Some + | Silverlight v -> FrameworkIdentifier.Silverlight(v) |> Some + | WindowsPhoneApp v -> FrameworkIdentifier.WindowsPhoneApp(v) |> Some + | WindowsPhoneSilverlight v -> FrameworkIdentifier.WindowsPhoneSilverlight(v) |> Some + | MonoAndroid _ -> Some FrameworkIdentifier.MonoAndroid + | MonoTouch _ -> Some FrameworkIdentifier.MonoTouch + | MonoMac _ -> Some FrameworkIdentifier.MonoMac + | XamariniOS _ -> Some FrameworkIdentifier.XamariniOS + | XamarinMac _ -> Some FrameworkIdentifier.XamarinMac + | _ -> None module FrameworkDetection = let private cache = System.Collections.Concurrent.ConcurrentDictionary<_,_>()