From 834787bd8e078ee4bfc24281547de5ee348b5b6a Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Tue, 3 Feb 2015 10:45:27 +0100 Subject: [PATCH] Allow to reference StyleCop.MSBuild targets files - references #516 --- RELEASE_NOTES.md | 3 + src/Paket.Core/InstallModel.fs | 10 +++ src/Paket.Core/ProjectFile.fs | 64 +++++++++++-------- .../InstallModel/ProcessingSpecs.fs | 20 +++++- .../InstallModel/Xml/FSharp.Data.SqlClient.fs | 2 +- .../Paket.Tests/InstallModel/Xml/Fantomas.fs | 2 +- .../InstallModel/Xml/FantomasLib.fs | 2 +- tests/Paket.Tests/InstallModel/Xml/Fuchu.fs | 2 +- tests/Paket.Tests/InstallModel/Xml/Plossum.fs | 2 +- tests/Paket.Tests/InstallModel/Xml/RxXaml.fs | 2 +- .../InstallModel/Xml/System.Spatial.fs | 2 +- .../InstallModel/Xml/SystemNetHttp.fs | 2 +- .../InstallModel/Xml/SystemNetHttpForNet4.fs | 2 +- ...mNetHttpWithExistingFrameworkReferences.fs | 2 +- .../SystemNetHttpWithFrameworkReferences.fs | 2 +- .../InstallModel/Xml/xunit.runner.fs | 4 +- tests/Paket.Tests/Paket.Tests.fsproj | 1 + 17 files changed, 82 insertions(+), 42 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 76cd636cec..039efbd2db 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,6 @@ +#### 0.27.0-alpha001 - 03.02.2015 +* Allow to reference `.props` and `.targets` files - https://github.com/fsprojects/Paket/issues/516 + #### 0.26.4 - 02.02.2015 * Create a install function in the api which takes a `paket.dependencies` file as text - https://github.com/fsprojects/Paket/issues/576 diff --git a/src/Paket.Core/InstallModel.fs b/src/Paket.Core/InstallModel.fs index dec96538bd..7db33dcbc0 100644 --- a/src/Paket.Core/InstallModel.fs +++ b/src/Paket.Core/InstallModel.fs @@ -105,6 +105,16 @@ type InstallModel = | _ -> None) |> Seq.choose id | None -> Seq.empty + + member this.GetTargetsFiles(target : TargetProfile) = + match Seq.tryFind (fun lib -> Seq.exists (fun t -> t = target) lib.Targets) this.LibFolders with + | Some folder -> folder.Files.References + |> Set.map (fun x -> + match x with + | Reference.TargetsFile targetsFile -> Some targetsFile + | _ -> None) + |> Seq.choose id + | None -> Seq.empty member this.AddLibFolders(libs : seq) : InstallModel = let libFolders = diff --git a/src/Paket.Core/ProjectFile.fs b/src/Paket.Core/ProjectFile.fs index 93fb96a216..4c521b7f26 100644 --- a/src/Paket.Core/ProjectFile.fs +++ b/src/Paket.Core/ProjectFile.fs @@ -267,34 +267,38 @@ type ProjectFile = |> List.map (fun lib -> PlatformMatching.getCondition lib.Targets,createItemGroup lib.Files.References,createPropertyGroup lib.Files.References) |> List.sortBy (fun (x,_,_) -> x) - match conditions with - | ["$(TargetFrameworkIdentifier) == 'true'",itemGroup,propertyGroup] -> Seq.empty,itemGroup - | _ -> - let chooseNode = this.CreateNode("Choose") + let chooseNode,additionalPropertyGroup = + match conditions with + | ["$(TargetFrameworkIdentifier) == 'true'",itemGroup,(propertyNames,propertyGroup)] -> itemGroup,if Set.isEmpty propertyNames then None else Some propertyGroup + | _ -> + let chooseNode = this.CreateNode("Choose") - conditions - |> List.map (fun (condition,itemGroup,(propertyNames,propertyGroup)) -> - let whenNode = - this.CreateNode("When") - |> addAttribute "Condition" condition - - if not itemGroup.IsEmpty then - whenNode.AppendChild(itemGroup) |> ignore - if not <| Set.isEmpty propertyNames then - whenNode.AppendChild(propertyGroup) |> ignore - whenNode) - |> List.iter(fun node -> chooseNode.AppendChild(node) |> ignore) - - let propertyNameNodes = conditions - |> List.map (fun (_,_,(propertyNames,_)) -> propertyNames) - |> Set.unionMany - |> Seq.map (fun propertyName -> - this.CreateNode("Import") - |> addAttribute "Project" (sprintf "$(%s)" propertyName) - |> addAttribute "Condition" (sprintf "Exists('$(%s)')" propertyName)) - - propertyNameNodes,chooseNode + |> List.map (fun (condition,itemGroup,(propertyNames,propertyGroup)) -> + let whenNode = + this.CreateNode("When") + |> addAttribute "Condition" condition + + if not itemGroup.IsEmpty then + whenNode.AppendChild(itemGroup) |> ignore + if not <| Set.isEmpty propertyNames then + whenNode.AppendChild(propertyGroup) |> ignore + whenNode) + |> List.iter(fun node -> chooseNode.AppendChild(node) |> ignore) + + chooseNode,None + + let propertyNameNodes = + conditions + |> List.map (fun (_,_,(propertyNames,_)) -> propertyNames) + |> Set.unionMany + |> Seq.map (fun propertyName -> + this.CreateNode("Import") + |> addAttribute "Project" (sprintf "$(%s)" propertyName) + |> addAttribute "Condition" (sprintf "Exists('$(%s)')" propertyName)) + |> Seq.toList + + propertyNameNodes,chooseNode,additionalPropertyGroup member this.UpdateReferences(completeModel: Map, usedPackages : Map, hard) = @@ -314,10 +318,14 @@ type ProjectFile = this.DeleteCustomModelNodes(kv.Value) let package = usedPackages.[kv.Key] this.GenerateXml(kv.Value,package.CopyLocal)) - |> Seq.iter (fun (propertyNameNodes,node) -> - if node.ChildNodes.Count > 0 then + |> Seq.iter (fun (propertyNameNodes,node,additionalPropertyGroup) -> + if node.ChildNodes.Count > 0 then this.ProjectNode.AppendChild node |> ignore + match additionalPropertyGroup with + | Some node -> this.ProjectNode.AppendChild node |> ignore + | None -> () + propertyNameNodes |> Seq.iter (this.ProjectNode.AppendChild >> ignore)) diff --git a/tests/Paket.Tests/InstallModel/ProcessingSpecs.fs b/tests/Paket.Tests/InstallModel/ProcessingSpecs.fs index 633e6daee2..c0a195a70f 100644 --- a/tests/Paket.Tests/InstallModel/ProcessingSpecs.fs +++ b/tests/Paket.Tests/InstallModel/ProcessingSpecs.fs @@ -82,8 +82,6 @@ let ``should install single client profile lib for everything``() = let model = emptymodel.AddReferences([ @"..\Castle.Core\lib\net40-client\Castle.Core.dll" ]) - // TODO: not sure it makes sense to include a 4.0 dll into a 3.5 project - // model.GetFiles(SinglePlatform (DotNetFramework FrameworkVersion.V3_5)) |> shouldNotContain @"..\Castle.Core\lib\net40-client\Castle.Core.dll" model.GetFiles(SinglePlatform (DotNetFramework FrameworkVersion.V4_Client)) |> shouldContain @"..\Castle.Core\lib\net40-client\Castle.Core.dll" model.GetFiles(SinglePlatform (DotNetFramework FrameworkVersion.V4)) |> shouldContain @"..\Castle.Core\lib\net40-client\Castle.Core.dll" model.GetFiles(SinglePlatform (DotNetFramework FrameworkVersion.V4_5)) |> shouldContain @"..\Castle.Core\lib\net40-client\Castle.Core.dll" @@ -439,3 +437,21 @@ let ``should not install tools``() = |> Seq.forall (fun folder -> folder.Files.References.IsEmpty) |> shouldEqual true +[] +let ``should handle props files``() = + let model = + emptymodel.AddTargetsFiles( + [ @"..\xunit.runner.visualstudio\build\net20\xunit.runner.visualstudio.props" + @"..\xunit.runner.visualstudio\build\portable-net45+aspnetcore50+win+wpa81+wp80+monotouch+monoandroid\xunit.runner.visualstudio.props" ]) + .FilterBlackList() + + model.GetTargetsFiles(SinglePlatform (DotNetFramework FrameworkVersion.V2)) |> shouldContain @"..\xunit.runner.visualstudio\build\net20\xunit.runner.visualstudio.props" + +[] +let ``should handle Targets files``() = + let model = + emptymodel.AddTargetsFiles( + [ @"..\StyleCop.MSBuild\build\StyleCop.MSBuild.Targets" ]) + .FilterBlackList() + + model.GetTargetsFiles(SinglePlatform (DotNetFramework FrameworkVersion.V2)) |> shouldContain @"..\StyleCop.MSBuild\build\StyleCop.MSBuild.Targets" \ No newline at end of file diff --git a/tests/Paket.Tests/InstallModel/Xml/FSharp.Data.SqlClient.fs b/tests/Paket.Tests/InstallModel/Xml/FSharp.Data.SqlClient.fs index ee1c1ef2e7..0cd4e5f50d 100644 --- a/tests/Paket.Tests/InstallModel/Xml/FSharp.Data.SqlClient.fs +++ b/tests/Paket.Tests/InstallModel/Xml/FSharp.Data.SqlClient.fs @@ -38,7 +38,7 @@ let ``should generate Xml for FSharp.Data.SqlClient 1.4.4``() = [], Nuspec.Load("Nuspec/FSharp.Data.SqlClient.nuspec")) - let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) |> snd + let _,chooseNode,_ = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) chooseNode.OuterXml |> normalizeXml |> shouldEqual (normalizeXml expected) diff --git a/tests/Paket.Tests/InstallModel/Xml/Fantomas.fs b/tests/Paket.Tests/InstallModel/Xml/Fantomas.fs index 1e18646b77..5898c60907 100644 --- a/tests/Paket.Tests/InstallModel/Xml/Fantomas.fs +++ b/tests/Paket.Tests/InstallModel/Xml/Fantomas.fs @@ -26,7 +26,7 @@ let ``should generate Xml for Fantomas 1.5``() = [], Nuspec.Explicit ["FantomasLib.dll"]) - let propertyNodes,chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) + let propertyNodes,chooseNode,additionalNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) chooseNode.OuterXml |> normalizeXml |> shouldEqual (normalizeXml expected) diff --git a/tests/Paket.Tests/InstallModel/Xml/FantomasLib.fs b/tests/Paket.Tests/InstallModel/Xml/FantomasLib.fs index 2ef1ae8751..7a797e3c54 100644 --- a/tests/Paket.Tests/InstallModel/Xml/FantomasLib.fs +++ b/tests/Paket.Tests/InstallModel/Xml/FantomasLib.fs @@ -26,7 +26,7 @@ let ``should generate Xml for Fantomas 1.5``() = [], Nuspec.Explicit ["FantomasLib.dll"]) - let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.False) |> snd + let _,chooseNode,_ = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.False) chooseNode.OuterXml |> normalizeXml |> shouldEqual (normalizeXml expected) diff --git a/tests/Paket.Tests/InstallModel/Xml/Fuchu.fs b/tests/Paket.Tests/InstallModel/Xml/Fuchu.fs index 09533a6a35..a554282ac8 100644 --- a/tests/Paket.Tests/InstallModel/Xml/Fuchu.fs +++ b/tests/Paket.Tests/InstallModel/Xml/Fuchu.fs @@ -26,7 +26,7 @@ let ``should generate Xml for Fuchu 0.4``() = [], Nuspec.All) - let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) |> snd + let _,chooseNode,_ = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) chooseNode.OuterXml |> normalizeXml |> shouldEqual (normalizeXml expected) diff --git a/tests/Paket.Tests/InstallModel/Xml/Plossum.fs b/tests/Paket.Tests/InstallModel/Xml/Plossum.fs index 3f2203957f..a17d452742 100644 --- a/tests/Paket.Tests/InstallModel/Xml/Plossum.fs +++ b/tests/Paket.Tests/InstallModel/Xml/Plossum.fs @@ -28,7 +28,7 @@ let ``should generate Xml for Plossum``() = [], Nuspec.All) - let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) |> snd + let _,chooseNode,_ = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) chooseNode.OuterXml |> normalizeXml |> shouldEqual (normalizeXml expected) \ No newline at end of file diff --git a/tests/Paket.Tests/InstallModel/Xml/RxXaml.fs b/tests/Paket.Tests/InstallModel/Xml/RxXaml.fs index 351258df7c..d8ffba6c52 100644 --- a/tests/Paket.Tests/InstallModel/Xml/RxXaml.fs +++ b/tests/Paket.Tests/InstallModel/Xml/RxXaml.fs @@ -107,7 +107,7 @@ let ``should generate Xml for Rx-XAML 2.2.4 with correct framework assembly refe { AssemblyName = "System.Windows"; FrameworkRestrictions = [FrameworkRestriction.Exactly(Silverlight "v5.0")] } { AssemblyName = "System.Windows"; FrameworkRestrictions = [FrameworkRestriction.Exactly(WindowsPhoneSilverlight "v7.1")] }]}) - let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) |> snd + let _,chooseNode,_ = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) chooseNode.OuterXml |> normalizeXml |> shouldEqual (normalizeXml expected) diff --git a/tests/Paket.Tests/InstallModel/Xml/System.Spatial.fs b/tests/Paket.Tests/InstallModel/Xml/System.Spatial.fs index 2cf1c6c958..84e0402d2a 100644 --- a/tests/Paket.Tests/InstallModel/Xml/System.Spatial.fs +++ b/tests/Paket.Tests/InstallModel/Xml/System.Spatial.fs @@ -44,7 +44,7 @@ let ``should generate Xml for System.Spatial``() = @"..\System.Spatial\lib\sl4\zh-Hans\System.Spatial.resources.dll" ],[],Nuspec.All) - let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) |> snd + let _,chooseNode,_ = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) chooseNode.OuterXml |> normalizeXml |> shouldEqual (normalizeXml expected) \ No newline at end of file diff --git a/tests/Paket.Tests/InstallModel/Xml/SystemNetHttp.fs b/tests/Paket.Tests/InstallModel/Xml/SystemNetHttp.fs index 9efe064d0e..59be4e590c 100644 --- a/tests/Paket.Tests/InstallModel/Xml/SystemNetHttp.fs +++ b/tests/Paket.Tests/InstallModel/Xml/SystemNetHttp.fs @@ -171,7 +171,7 @@ let ``should generate Xml for System.Net.Http 2.2.8``() = [], Nuspec.All) - let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) |> snd + let _,chooseNode,_ = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) chooseNode.OuterXml |> normalizeXml |> shouldEqual (normalizeXml expected) diff --git a/tests/Paket.Tests/InstallModel/Xml/SystemNetHttpForNet4.fs b/tests/Paket.Tests/InstallModel/Xml/SystemNetHttpForNet4.fs index 4d65027955..47083c57bb 100644 --- a/tests/Paket.Tests/InstallModel/Xml/SystemNetHttpForNet4.fs +++ b/tests/Paket.Tests/InstallModel/Xml/SystemNetHttpForNet4.fs @@ -68,7 +68,7 @@ let ``should generate Xml for System.Net.Http 2.2.8``() = [], Nuspec.All) - let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) |> snd + let _,chooseNode,_ = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) chooseNode.OuterXml |> normalizeXml |> shouldEqual (normalizeXml expected) diff --git a/tests/Paket.Tests/InstallModel/Xml/SystemNetHttpWithExistingFrameworkReferences.fs b/tests/Paket.Tests/InstallModel/Xml/SystemNetHttpWithExistingFrameworkReferences.fs index 85cbcd5e70..4b35df6ae1 100644 --- a/tests/Paket.Tests/InstallModel/Xml/SystemNetHttpWithExistingFrameworkReferences.fs +++ b/tests/Paket.Tests/InstallModel/Xml/SystemNetHttpWithExistingFrameworkReferences.fs @@ -66,7 +66,7 @@ let ``should generate Xml for System.Net.Http 2.2.8``() = [{ AssemblyName = "System.Net.Http"; FrameworkRestrictions = [FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V4_5))] } { AssemblyName = "System.Net.Http.WebRequest"; FrameworkRestrictions = [FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V4_5))] }]}) - let chooseNode = ProjectFile.Load("./ProjectFile/TestData/FrameworkAssemblies.fsprojtest").Value.GenerateXml(model,CopyLocal.True) |> snd + let _,chooseNode,_ = ProjectFile.Load("./ProjectFile/TestData/FrameworkAssemblies.fsprojtest").Value.GenerateXml(model,CopyLocal.True) chooseNode.OuterXml |> normalizeXml |> shouldEqual (normalizeXml expected) diff --git a/tests/Paket.Tests/InstallModel/Xml/SystemNetHttpWithFrameworkReferences.fs b/tests/Paket.Tests/InstallModel/Xml/SystemNetHttpWithFrameworkReferences.fs index 5406cb1f8f..9b3ba33279 100644 --- a/tests/Paket.Tests/InstallModel/Xml/SystemNetHttpWithFrameworkReferences.fs +++ b/tests/Paket.Tests/InstallModel/Xml/SystemNetHttpWithFrameworkReferences.fs @@ -74,7 +74,7 @@ let ``should generate Xml for System.Net.Http 2.2.8``() = [{ AssemblyName = "System.Net.Http"; FrameworkRestrictions = [FrameworkRestriction.AtLeast(DotNetFramework(FrameworkVersion.V4_5))] } { AssemblyName = "System.Net.Http.WebRequest"; FrameworkRestrictions = [FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V4_5))] }]}) - let chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) |> snd + let _,chooseNode,_ = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) chooseNode.OuterXml |> normalizeXml |> shouldEqual (normalizeXml expected) diff --git a/tests/Paket.Tests/InstallModel/Xml/xunit.runner.fs b/tests/Paket.Tests/InstallModel/Xml/xunit.runner.fs index 6cae80485a..2a9e5cb53e 100644 --- a/tests/Paket.Tests/InstallModel/Xml/xunit.runner.fs +++ b/tests/Paket.Tests/InstallModel/Xml/xunit.runner.fs @@ -32,11 +32,13 @@ let ``should generate Xml for xunit.runner.visualstudio 2.0.0``() = @"..\xunit.runner.visualstudio\build\portable-net45+aspnetcore50+win+wpa81+wp80+monotouch+monoandroid\xunit.runner.visualstudio.props" ], Nuspec.All) - let propertyNodes,chooseNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) + let propertyNodes,chooseNode,additionalNode = ProjectFile.Load("./ProjectFile/TestData/Empty.fsprojtest").Value.GenerateXml(model,CopyLocal.True) chooseNode.OuterXml |> normalizeXml |> shouldEqual (normalizeXml expected) + additionalNode |> shouldEqual None + propertyNodes |> Seq.length |> shouldEqual 1 (propertyNodes |> Seq.head).OuterXml diff --git a/tests/Paket.Tests/Paket.Tests.fsproj b/tests/Paket.Tests/Paket.Tests.fsproj index d7c0f93149..768789a558 100644 --- a/tests/Paket.Tests/Paket.Tests.fsproj +++ b/tests/Paket.Tests/Paket.Tests.fsproj @@ -210,6 +210,7 @@ +