diff --git a/src/Paket.Core/ProjectFile.fs b/src/Paket.Core/ProjectFile.fs index 6bbf9ad2d1..8b687f0feb 100644 --- a/src/Paket.Core/ProjectFile.fs +++ b/src/Paket.Core/ProjectFile.fs @@ -13,12 +13,19 @@ open Paket.Requirements [] type BuildAction = | Compile | Content | Reference + | Resource | Page // These two are WPF only - https://msdn.microsoft.com/library/aa970494%28v=vs.100%29.aspx?f=255&MSPPError=-2147217396 + // There are some other build actions - http://stackoverflow.com/questions/145752/what-are-the-various-build-action-settings-in-visual-studio-project-properties/145769#145769 override this.ToString() = match this with | Compile -> "Compile" | Content -> "Content" | Reference -> "Reference" + | Resource -> "Resource" + | Page -> "Page" + + static member PaketFileNodeNames = + [Compile; Content; Resource; Page] |> List.map (fun x->x.ToString()) /// File item inside of project files. type FileItem = @@ -545,11 +552,15 @@ module ProjectFile = | None -> [BuildAction.Content, createNode "ItemGroup" project BuildAction.Compile, createNode "ItemGroup" project - BuildAction.Reference, createNode "ItemGroup" project ] + BuildAction.Reference, createNode "ItemGroup" project + BuildAction.Resource, createNode "ItemGroup" project + BuildAction.Page, createNode "ItemGroup" project ] | Some node -> [BuildAction.Content, node :?> XmlElement - BuildAction.Compile, node :?> XmlElement - BuildAction.Reference, node :?> XmlElement ] + BuildAction.Compile, node :?> XmlElement + BuildAction.Reference, node :?> XmlElement + BuildAction.Resource, node :?> XmlElement + BuildAction.Page, node :?> XmlElement ] |> dict for fileItem in fileItems |> List.rev do @@ -569,6 +580,10 @@ module ProjectFile = node |> addChild (createNodeSet "HintPath" fileItem.Include project) |> addChild (createNodeSet "Private" "True" project) + | BuildAction.Page -> + node + |> addChild (createNodeSet "Generator" "MSBuild:Compile" project) + |> addChild (createNodeSet "SubType" "Designer" project) | _ -> node |> fun n -> if fileItem.WithPaketSubNode then addChild (createNodeSet "Paket" "True" project) n else n |> fun n -> match fileItem.CopyToOutputDirectory with @@ -611,11 +626,12 @@ module ProjectFile = | None -> let firstNode = fileItemsInSameDir |> Seq.head firstNode.ParentNode.InsertBefore(libReferenceNode, firstNode) |> ignore - - let paketNodes = - (findPaketNodes "Compile" project) - @ (findPaketNodes "Content" project) - + + let paketNodes = + BuildAction.PaketFileNodeNames + |> List.map (fun name -> findPaketNodes name project) + |> List.concat + // remove unneeded files for paketNode in paketNodes do match getAttribute "Include" paketNode with @@ -969,8 +985,9 @@ module ProjectFile = File.SetLastWriteTimeUtc(project.FileName, DateTime.UtcNow) let getPaketFileItems project = - findPaketNodes "Content" project - |> List.append <| findPaketNodes "Compile" project + BuildAction.PaketFileNodeNames + |> List.map (fun name -> findPaketNodes name project) + |> List.concat |> List.map (fun n -> FileInfo(Path.Combine(Path.GetDirectoryName project.FileName, n.Attributes.["Include"].Value))) let getProjectGuid project = @@ -1122,9 +1139,15 @@ module ProjectFile = |> Option.iter (fun n -> n.ParentNode.RemoveChild n |> ignore) let determineBuildAction fileName (project:ProjectFile) = - if Path.GetExtension project.FileName = Path.GetExtension fileName + "proj" - then BuildAction.Compile - else BuildAction.Content + match (Path.GetExtension fileName).ToLowerInvariant() with + | ext when Path.GetExtension project.FileName = ext + "proj" + -> BuildAction.Compile + | ".xaml" -> BuildAction.Page + | ".ttf" | ".png" | ".ico" | ".jpg" | ".jpeg"| ".bmp" | ".gif" + | ".wav" | ".mid" | ".midi"| ".wma" | ".mp3" | ".ogg" | ".rma" + | ".avi" | ".mp4" | ".divx"| ".wmv" //TODO: and other media types + -> BuildAction.Resource + | _ -> BuildAction.Content let determineBuildActionForRemoteItems fileName (project:ProjectFile) = if Path.GetExtension fileName = ".dll" diff --git a/tests/Paket.Tests/ProjectFile/FileBuildActionSpecs.fs b/tests/Paket.Tests/ProjectFile/FileBuildActionSpecs.fs index 1ab948248b..f1682560fc 100644 --- a/tests/Paket.Tests/ProjectFile/FileBuildActionSpecs.fs +++ b/tests/Paket.Tests/ProjectFile/FileBuildActionSpecs.fs @@ -23,5 +23,19 @@ let ``should recognize compilable files``() = let ``should recognize content files``() = (createProject "A.csproj").DetermineBuildAction "Something.js" |> shouldEqual BuildAction.Content (createProject "B.fsproj").DetermineBuildAction "config.yml" |> shouldEqual BuildAction.Content - (createProject "C.vbproj").DetermineBuildAction "noext" |> shouldEqual BuildAction.Content - (createProject "D.nproj").DetermineBuildAction "App.config" |> shouldEqual BuildAction.Content \ No newline at end of file + (createProject "C.vbproj").DetermineBuildAction "noext" |> shouldEqual BuildAction.Content + (createProject "D.nproj").DetermineBuildAction "App.config" |> shouldEqual BuildAction.Content + +[] +let ``should recognize page files``() = + (createProject "A.csproj").DetermineBuildAction "Form1.xaml" |> shouldEqual BuildAction.Page + (createProject "B.fsproj").DetermineBuildAction "Form1.Xaml" |> shouldEqual BuildAction.Page + (createProject "C.vbproj").DetermineBuildAction "Form1.XAML" |> shouldEqual BuildAction.Page + (createProject "D.nproj" ).DetermineBuildAction "Form1.XaML" |> shouldEqual BuildAction.Page + +[] +let ``should recognize resource files``() = + (createProject "A.csproj").DetermineBuildAction "Form1.ttf" |> shouldEqual BuildAction.Resource + (createProject "B.fsproj").DetermineBuildAction "Form1.ico" |> shouldEqual BuildAction.Resource + (createProject "C.vbproj").DetermineBuildAction "Form1.png" |> shouldEqual BuildAction.Resource + (createProject "D.nproj" ).DetermineBuildAction "Form1.jpg" |> shouldEqual BuildAction.Resource diff --git a/tests/Paket.Tests/ProjectFile/OutputSpecs.fs b/tests/Paket.Tests/ProjectFile/OutputSpecs.fs index 422eac11dc..d857fa8b79 100644 --- a/tests/Paket.Tests/ProjectFile/OutputSpecs.fs +++ b/tests/Paket.Tests/ProjectFile/OutputSpecs.fs @@ -78,7 +78,7 @@ let ``should maintain order when updating project file items`` () = let rec nodes node = seq { for node in node |> Seq.cast do - if node.Name ="Compile" || node.Name = "Content" + if List.contains node.Name BuildAction.PaketFileNodeNames then yield Paket.Xml.getAttribute "Include" node yield! nodes node } @@ -120,7 +120,7 @@ let ``should remove missing files that exist in the project`` () = let rec nodes node = seq { for node in node |> Seq.cast do - if node.Name ="Compile" || node.Name = "Content" + if List.contains node.Name BuildAction.PaketFileNodeNames then yield Paket.Xml.getAttribute "Include" node yield! nodes node }