diff --git a/src/Paket.Core/ProjectFile.fs b/src/Paket.Core/ProjectFile.fs
index 0785ea4429..5ba7a87004 100644
--- a/src/Paket.Core/ProjectFile.fs
+++ b/src/Paket.Core/ProjectFile.fs
@@ -129,8 +129,6 @@ type ProjectFile =
node.ParentNode.RemoveChild(node) |> ignore
member this.UpdateFileItems(fileItems : FileItem list, hard) =
- this.DeletePaketNodes("Compile")
- this.DeletePaketNodes("Content")
let firstItemGroup = this.ProjectNode |> getNodes "ItemGroup" |> Seq.firstOrDefault
@@ -144,7 +142,6 @@ type ProjectFile =
"Compile", node :?> XmlElement ]
|> dict
-
for fileItem in fileItems |> List.rev do
let libReferenceNode =
this.CreateNode(fileItem.BuildAction)
@@ -161,6 +158,7 @@ type ProjectFile =
match node |> getAttribute "Include" with
| Some path when path.StartsWith(Path.GetDirectoryName(fileItem.Include)) -> true
| _ -> false)
+
if Seq.isEmpty fileItemsInSameDir then
newItemGroups.[fileItem.BuildAction].PrependChild(libReferenceNode) |> ignore
@@ -177,9 +175,22 @@ type ProjectFile =
then existingNode :?> XmlElement |> addChild (this.CreateNode("Paket","True")) |> ignore
else verbosefn " - custom nodes for %s in %s ==> skipping" fileItem.Include this.FileName
| None ->
- let firstNode = fileItemsInSameDir |> Seq.head
+ let firstNode = fileItemsInSameDir |> Seq.head
firstNode.ParentNode.InsertBefore(libReferenceNode, firstNode) |> ignore
+ let paketNodes =
+ this.FindPaketNodes("Compile")
+ @ this.FindPaketNodes("Content")
+
+ //remove uneeded files
+ for paketNode in paketNodes do
+ match getAttribute "Include" paketNode with
+ | Some path ->
+ if not(fileItems |> List.exists (fun fi -> fi.Include = path))
+ then paketNode.ParentNode.RemoveChild(paketNode) |> ignore
+ else ()
+ | _ -> ()
+
this.DeleteIfEmpty("PropertyGroup")
this.DeleteIfEmpty("ItemGroup")
this.DeleteIfEmpty("Choose")
diff --git a/src/Paket/Paket.fsproj b/src/Paket/Paket.fsproj
index 187d748911..0deda55ffa 100644
--- a/src/Paket/Paket.fsproj
+++ b/src/Paket/Paket.fsproj
@@ -30,7 +30,7 @@
update
Project
paket.exe
- c:\code\Paket09x
+ D:\Appdev\officeprovider\
pdbonly
diff --git a/tests/Paket.Tests/Paket.Tests.fsproj b/tests/Paket.Tests/Paket.Tests.fsproj
index 1cffe81936..1996a48f55 100644
--- a/tests/Paket.Tests/Paket.Tests.fsproj
+++ b/tests/Paket.Tests/Paket.Tests.fsproj
@@ -218,6 +218,9 @@
Always
+
+ Always
+
diff --git a/tests/Paket.Tests/ProjectFile/OutputSpecs.fs b/tests/Paket.Tests/ProjectFile/OutputSpecs.fs
index 183fef4f1b..01554d8d12 100644
--- a/tests/Paket.Tests/ProjectFile/OutputSpecs.fs
+++ b/tests/Paket.Tests/ProjectFile/OutputSpecs.fs
@@ -3,6 +3,8 @@
open Paket
open NUnit.Framework
open FsUnit
+open System.Xml
+open System.Xml.Linq
[]
let ``should detect lib output type for Project1 proj file``() =
@@ -51,3 +53,86 @@ let ``should detect assembly name for Project3 proj file`` () =
ProjectFile.Load("./ProjectFile/TestData/Project3.fsprojtest").Value.GetAssemblyName()
|> shouldEqual ("Paket.Tests.Win.exe")
+[]
+let ``should maintain order when updating project file items`` () =
+
+ let projFile = ProjectFile.Load("./ProjectFile/TestData/MaintainsOrdering.fsprojtest").Value
+ let fileItems = [
+ { BuildAction = "Compile"; Include = "..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\Pluralizer.fs"; Link = Some("fsharp_data\\Pluralizer.fs") }
+ { BuildAction = "Compile"; Include = "..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\NameUtils.fs"; Link = Some("fsharp_data\\NameUtils.fs") }
+ { BuildAction = "Compile"; Include = "..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\TextConversions.fs"; Link = Some("fsharp_data\\TextConversions.fs") }
+ { BuildAction = "Compile"; Include = "..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\StructuralTypes.fs"; Link = Some("fsharp_data\\StructuralTypes.fs") }
+ { BuildAction = "Compile"; Include = "..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\StructuralInference.fs"; Link = Some("fsharp_data\\StructuralInference.fs") }
+ { BuildAction = "Compile"; Include = "..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\TextRuntime.fs"; Link = Some("fsharp_data\\TextRuntime.fs") }
+ { BuildAction = "Compile"; Include = "DebugProvidedTypes.fs"; Link = None }
+ { BuildAction = "Compile"; Include = "ProvidedTypes.fs"; Link = None }
+ { BuildAction = "Content"; Include = "ProvidedTypes.fsi"; Link = None }
+ ]
+ projFile.UpdateFileItems(fileItems, false)
+
+ let rec nodes node =
+ seq {
+ for node in node |> Seq.cast do
+ if node.Name = "Compile" || node.Name = "Content"
+ then yield Paket.Xml.getAttribute "Include" node
+ yield! nodes node
+ }
+
+ let actual =
+ nodes projFile.Document
+ |> Seq.choose id
+ |> Seq.toList
+ let expected =
+ [
+ "..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\Pluralizer.fs"
+ "..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\NameUtils.fs"
+ "..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\TextConversions.fs"
+ "..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\StructuralTypes.fs"
+ "..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\StructuralInference.fs"
+ "..\\..\\paket-files\\fsharp\\FSharp.Data\\src\\CommonRuntime\\TextRuntime.fs"
+ "ProvidedTypes.fsi"
+ "ProvidedTypes.fs"
+ "DebugProvidedTypes.fs"
+ "QuotationHelpers.fs"
+ "CommonTypes.fs"
+ "ExcelProvider.fs"
+ "WordProvider.fs"
+ "ProviderEntryPoint.fs"
+ ]
+ CollectionAssert.AreEqual(expected, actual)
+
+[]
+let ``should remove missing files that exist in the project`` () =
+
+ let projFile = ProjectFile.Load("./ProjectFile/TestData/MaintainsOrdering.fsprojtest").Value
+ let fileItems = [
+ { BuildAction = "Compile"; Include = "DebugProvidedTypes.fs"; Link = None }
+ { BuildAction = "Compile"; Include = "ProvidedTypes.fs"; Link = None }
+ { BuildAction = "Content"; Include = "ProvidedTypes.fsi"; Link = None }
+ ]
+ projFile.UpdateFileItems(fileItems, false)
+
+ let rec nodes node =
+ seq {
+ for node in node |> Seq.cast do
+ if node.Name = "Compile" || node.Name = "Content"
+ then yield Paket.Xml.getAttribute "Include" node
+ yield! nodes node
+ }
+
+ let actual =
+ nodes projFile.Document
+ |> Seq.choose id
+ |> Seq.toList
+ let expected =
+ [
+ "ProvidedTypes.fsi"
+ "ProvidedTypes.fs"
+ "DebugProvidedTypes.fs"
+ "QuotationHelpers.fs"
+ "CommonTypes.fs"
+ "ExcelProvider.fs"
+ "WordProvider.fs"
+ "ProviderEntryPoint.fs"
+ ]
+ CollectionAssert.AreEqual(expected, actual)
\ No newline at end of file
diff --git a/tests/Paket.Tests/ProjectFile/TestData/MaintainsOrdering.fsprojtest b/tests/Paket.Tests/ProjectFile/TestData/MaintainsOrdering.fsprojtest
new file mode 100644
index 0000000000..2c528c73ec
--- /dev/null
+++ b/tests/Paket.Tests/ProjectFile/TestData/MaintainsOrdering.fsprojtest
@@ -0,0 +1,125 @@
+
+
+
+
+ Debug
+ AnyCPU
+ 2.0
+ b8134fc6-3f15-4f95-baac-e5b2c7856060
+ Library
+ OfficeProvider
+ OfficeProvider
+ v4.0
+ 4.3.1.0
+ OfficeProvider
+
+ ..\..\
+
+
+ true
+ full
+ false
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ 3
+ bin\Debug\OfficeProvider.XML
+ D:\Appdev\officeprovider\tests\test.sln
+ Program
+ devenv.exe
+
+
+ pdbonly
+ true
+ true
+ bin\Release\
+ TRACE
+ 3
+ bin\Release\OfficeProvider.XML
+
+
+ 11
+
+
+
+
+ $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets
+
+
+
+
+ $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets
+
+
+
+
+
+
+
+
+
+ True
+ fsharp_data/Pluralizer.fs
+
+
+ True
+ fsharp_data/NameUtils.fs
+
+
+ True
+ fsharp_data/TextConversions.fs
+
+
+ True
+ fsharp_data/StructuralTypes.fs
+
+
+ True
+ fsharp_data/StructuralInference.fs
+
+
+ True
+ fsharp_data/TextRuntime.fs
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+
+
+
+
+
+
+
+
+
+
+ True
+
+
+
+
+
+
+
+
+
+ ..\..\packages\DocumentFormat.OpenXml\lib\DocumentFormat.OpenXml.dll
+ True
+ True
+
+
+
\ No newline at end of file