diff --git a/src/Paket.Core/Installation/RestoreProcess.fs b/src/Paket.Core/Installation/RestoreProcess.fs index 972eb5bbf3..c7ed398b8c 100644 --- a/src/Paket.Core/Installation/RestoreProcess.fs +++ b/src/Paket.Core/Installation/RestoreProcess.fs @@ -314,20 +314,22 @@ let createPaketPropsFile (lockFile:LockFile) (cliTools:ResolvedPackage seq) (pac | ExplicitRestriction fw -> ExplicitRestriction fw | _ -> group.Options.Settings.FrameworkRestrictions let condition = getExplicitRestriction restrictions - p,condition,packageSettings) - |> Seq.groupBy (fun (_,c,__) -> c) - |> Seq.collect (fun (condition,packages) -> - let condition = + + p,condition,packageSettings,group.Options.Settings.ReferenceCondition) + |> Seq.groupBy (fun (_,c,__,rc) -> c,rc) + |> Seq.collect (fun ((condition,referenceCondition),packages) -> + let targets = match condition with - | FrameworkRestriction.HasNoRestriction -> "" - | restrictions -> restrictions.ToMSBuildCondition() + | FrameworkRestriction.HasNoRestriction -> Set.empty + | restrictions -> restrictions.RepresentedFrameworks + let condition = PlatformMatching.getCondition referenceCondition targets let condition = if condition = "" || condition = "true" then "" else sprintf " AND (%s)" condition let packageReferences = packages - |> Seq.collect (fun (p,_,packageSettings) -> + |> Seq.collect (fun (p,_,packageSettings,__) -> [yield sprintf """ """ p.Name yield sprintf """ %O""" p.Version let excludeAssets = diff --git a/tests/Paket.Tests/InstallModel/PaketPropsTests.fs b/tests/Paket.Tests/InstallModel/PaketPropsTests.fs index 03675ba766..2550579e4a 100644 --- a/tests/Paket.Tests/InstallModel/PaketPropsTests.fs +++ b/tests/Paket.Tests/InstallModel/PaketPropsTests.fs @@ -19,8 +19,8 @@ let checkTargetFrameworkCondition msbuildCondition (itemGroup: XElement) = let checkTargetFrameworkNoRestriction itemGroup = checkTargetFrameworkCondition "" itemGroup -let checkTargetFrameworkRestriction r itemGroup = - let msbuildCond = r |> Paket.Requirements.getExplicitRestriction |> fun c -> c.ToMSBuildCondition() +let checkTargetFrameworkRestriction rc r itemGroup = + let msbuildCond = r |> Paket.Requirements.getExplicitRestriction |> fun c -> PlatformMatching.getCondition rc c.RepresentedFrameworks checkTargetFrameworkCondition (sprintf " AND (%s)" msbuildCond) itemGroup let checkContainsPackageRefs pkgRefs (group: XElement) = @@ -186,11 +186,127 @@ group Other1 match itemGroups with | [groupMain; otherGroup] -> groupMain - |> checkTargetFrameworkRestriction lockFile.Groups.[Constants.MainDependencyGroup].Options.Settings.FrameworkRestrictions + |> checkTargetFrameworkRestriction lockFile.Groups.[Constants.MainDependencyGroup].Options.Settings.ReferenceCondition lockFile.Groups.[Constants.MainDependencyGroup].Options.Settings.FrameworkRestrictions groupMain |> checkContainsPackageRefs [ "FSharp.Core","3.1.2.5"; "Argu","4.2.1" ] otherGroup - |> checkTargetFrameworkRestriction lockFile.Groups.[Domain.GroupName "Other1"].Options.Settings.FrameworkRestrictions + |> checkTargetFrameworkRestriction lockFile.Groups.[Domain.GroupName "Other1"].Options.Settings.ReferenceCondition lockFile.Groups.[Domain.GroupName "Other1"].Options.Settings.FrameworkRestrictions + otherGroup + |> checkContainsPackageRefs [ "FSharp.Core","4.3.4"; "FsCheck","2.8.2" ] + | l -> + Assert.Fail(sprintf "expected two ItemGroup but was '%A'" l) + +[] +let ``should create props file for design mode with group conditions``() = + + let lockFile = """CONDITION: COND_MAIN +NUGET + remote: https://api.nuget.org/v3/index.json + Argu (4.2.1) + FSharp.Core (>= 3.1.2) + FSharp.Core (3.1.2.5) + +GROUP Other1 +CONDITION: COND_OTHER1 +NUGET + remote: https://api.nuget.org/v3/index.json + FsCheck (2.8.2) + FSharp.Core (>= 3.1.2.5) + FSharp.Core (4.3.4) +""" + + let refFileContent = """ +FSharp.Core +Argu + +group Other1 + FSharp.Core + FsCheck +""" + + let lockFile = LockFile.Parse("", toLines lockFile) + + let refFile = ReferencesFile.FromLines(toLines refFileContent) + + let packages = + [ for kv in refFile.Groups do + let packagesInGroup,_ = lockFile.GetOrderedPackageHull(kv.Key, refFile) + yield! packagesInGroup ] + + let outPath = System.IO.Path.GetTempFileName() + Paket.RestoreProcess.createPaketPropsFile lockFile Seq.empty packages (FileInfo outPath) + + let doc = XDocument.Load(outPath, LoadOptions.PreserveWhitespace) + + let itemGroups = doc.Root.Elements (xname "ItemGroup") |> Seq.toList + + match itemGroups with + | [groupMain; otherGroup] -> + groupMain + |> checkTargetFrameworkRestriction lockFile.Groups.[Constants.MainDependencyGroup].Options.Settings.ReferenceCondition lockFile.Groups.[Constants.MainDependencyGroup].Options.Settings.FrameworkRestrictions + groupMain + |> checkContainsPackageRefs [ "FSharp.Core","3.1.2.5"; "Argu","4.2.1" ] + otherGroup + |> checkTargetFrameworkRestriction lockFile.Groups.[Domain.GroupName "Other1"].Options.Settings.ReferenceCondition lockFile.Groups.[Domain.GroupName "Other1"].Options.Settings.FrameworkRestrictions + otherGroup + |> checkContainsPackageRefs [ "FSharp.Core","4.3.4"; "FsCheck","2.8.2" ] + | l -> + Assert.Fail(sprintf "expected two ItemGroup but was '%A'" l) + +[] +let ``should create props file for design mode with group restrictions and conditions``() = + + let lockFile = """CONDITION: COND_MAIN +RESTRICTION: && (>= net461) (< net47) +NUGET + remote: https://api.nuget.org/v3/index.json + Argu (4.2.1) + FSharp.Core (>= 3.1.2) + FSharp.Core (3.1.2.5) + +GROUP Other1 +CONDITION: COND_OTHER1 +RESTRICTION: == netstandard2.0 +NUGET + remote: https://api.nuget.org/v3/index.json + FsCheck (2.8.2) + FSharp.Core (>= 3.1.2.5) + FSharp.Core (4.3.4) +""" + + let refFileContent = """ +FSharp.Core +Argu + +group Other1 + FSharp.Core + FsCheck +""" + + let lockFile = LockFile.Parse("", toLines lockFile) + + let refFile = ReferencesFile.FromLines(toLines refFileContent) + + let packages = + [ for kv in refFile.Groups do + let packagesInGroup,_ = lockFile.GetOrderedPackageHull(kv.Key, refFile) + yield! packagesInGroup ] + + let outPath = System.IO.Path.GetTempFileName() + Paket.RestoreProcess.createPaketPropsFile lockFile Seq.empty packages (FileInfo outPath) + + let doc = XDocument.Load(outPath, LoadOptions.PreserveWhitespace) + + let itemGroups = doc.Root.Elements (xname "ItemGroup") |> Seq.toList + + match itemGroups with + | [groupMain; otherGroup] -> + groupMain + |> checkTargetFrameworkRestriction lockFile.Groups.[Constants.MainDependencyGroup].Options.Settings.ReferenceCondition lockFile.Groups.[Constants.MainDependencyGroup].Options.Settings.FrameworkRestrictions + groupMain + |> checkContainsPackageRefs [ "FSharp.Core","3.1.2.5"; "Argu","4.2.1" ] + otherGroup + |> checkTargetFrameworkRestriction lockFile.Groups.[Domain.GroupName "Other1"].Options.Settings.ReferenceCondition lockFile.Groups.[Domain.GroupName "Other1"].Options.Settings.FrameworkRestrictions otherGroup |> checkContainsPackageRefs [ "FSharp.Core","4.3.4"; "FsCheck","2.8.2" ] | l -> @@ -243,17 +359,17 @@ group Other2 match itemGroups with | [groupMain; otherGroup20And21; otherGroupOnly21] -> groupMain - |> checkTargetFrameworkRestriction lockFile.Groups.[Constants.MainDependencyGroup].Options.Settings.FrameworkRestrictions + |> checkTargetFrameworkRestriction lockFile.Groups.[Constants.MainDependencyGroup].Options.Settings.ReferenceCondition lockFile.Groups.[Constants.MainDependencyGroup].Options.Settings.FrameworkRestrictions groupMain |> checkContainsPackageRefs [ "FSharp.Core","3.1.2.5"; "Argu","4.2.1" ] otherGroup20And21 - |> checkTargetFrameworkRestriction lockFile.Groups.[Domain.GroupName "Other2"].Options.Settings.FrameworkRestrictions + |> checkTargetFrameworkRestriction lockFile.Groups.[Domain.GroupName "Other2"].Options.Settings.ReferenceCondition lockFile.Groups.[Domain.GroupName "Other2"].Options.Settings.FrameworkRestrictions otherGroup20And21 |> checkContainsPackageRefs [ "FSharp.Core","4.3.4" ] otherGroupOnly21 - |> checkTargetFrameworkRestriction lockFile.Groups.[Domain.GroupName "Other2"].Resolution.[Domain.PackageName "FsCheck"].Settings.FrameworkRestrictions + |> checkTargetFrameworkRestriction lockFile.Groups.[Domain.GroupName "Other2"].Options.Settings.ReferenceCondition lockFile.Groups.[Domain.GroupName "Other2"].Resolution.[Domain.PackageName "FsCheck"].Settings.FrameworkRestrictions otherGroupOnly21 |> checkContainsPackageRefs [ "FsCheck","2.8.2" ] | l -> @@ -286,11 +402,11 @@ Newtonsoft.Json let doc = XDocument.Load(outPath, LoadOptions.PreserveWhitespace) let itemGroups = doc.Root.Elements (xname "ItemGroup") |> Seq.toList - + match itemGroups with | [groupMain] -> groupMain - |> checkTargetFrameworkRestriction lockFile.Groups.[Constants.MainDependencyGroup].Resolution.[Domain.PackageName "Newtonsoft.Json"].Settings.FrameworkRestrictions + |> checkTargetFrameworkRestriction lockFile.Groups.[Constants.MainDependencyGroup].Options.Settings.ReferenceCondition lockFile.Groups.[Constants.MainDependencyGroup].Resolution.[Domain.PackageName "Newtonsoft.Json"].Settings.FrameworkRestrictions groupMain |> checkContainsPackageRefs [ "Newtonsoft.Json","11.0.2" ] | l ->