Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 26 additions & 27 deletions src/Paket.Core/PaketConfigFiles/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2039,32 +2039,31 @@ type ProjectFile with

let getCompileItem (projectFile, compileNode) =
let projectFolder = projectFile.FileName |> Path.GetFullPath |> Path.GetDirectoryName
let sourceFile =
let file =
match compileNode |> getAttribute "Include" with
| Some file -> file
| None ->
match compileNode |> getAttribute "Update" with
| Some file -> file
| None -> failwithf "The Compile entry is in unknown format and doesn't contain a Update or Include attribute."

file
|> normalizePath
|> fun relPath -> Path.Combine(projectFolder, relPath)

let destPath =
compileNode
|> getDescendants "Link"
|> function
| [] -> createRelativePath (projectFolder + string Path.DirectorySeparatorChar) sourceFile
| linkNode :: _ -> linkNode.InnerText
|> normalizePath
|> Path.GetDirectoryName
{
SourceFile = sourceFile
DestinationPath = destPath
BaseDir = projectFolder
}
match compileNode |> getAttribute "Include" |> Option.orElseWith (fun () -> compileNode |> getAttribute "Update") with
| None ->
// Entries such as <Compile Remove="..." /> without an Include or Update attribute
// don't reference a source file, so they can't produce a compile item. Skip them
// instead of failing the whole pack/build (see GitHub issue #4222).
None
| Some file ->
let sourceFile =
file
|> normalizePath
|> fun relPath -> Path.Combine(projectFolder, relPath)

let destPath =
compileNode
|> getDescendants "Link"
|> function
| [] -> createRelativePath (projectFolder + string Path.DirectorySeparatorChar) sourceFile
| linkNode :: _ -> linkNode.InnerText
|> normalizePath
|> Path.GetDirectoryName
Some {
SourceFile = sourceFile
DestinationPath = destPath
BaseDir = projectFolder
}

let getRealItems compileItem =
let sourceFolder = Path.GetDirectoryName(compileItem.SourceFile)
Expand All @@ -2080,7 +2079,7 @@ type ProjectFile with
this.GetProjects includeReferencedProjects cache
|> this.ProjectsWithoutTemplates
|> Seq.collect getCompileRefs
|> Seq.map getCompileItem
|> Seq.choose getCompileItem
|> Seq.collect getRealItems


Expand Down
1 change: 1 addition & 0 deletions tests/Paket.Tests/Paket.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
<Compile Include="LocalFile\LocalFileSpecs.fs" />
<Compile Include="Simplifier\BasicScenarioSpecs.fs" />
<TestAsset Include="ProjectFile\TestData\MicrosoftNetSdkWithTargetFrameworkAndOutputPath.csprojtest" />
<TestAsset Include="ProjectFile\TestData\CompileRemoveOnly.csprojtest" />
<TestAsset Include="ProjectFile\TestData\EmptyFsharpGuid.fsprojtest" />
<TestAsset Include="ProjectFile\TestData\EmptyVbGuid.vbprojtest" />
<TestAsset Include="ProjectFile\TestData\EmptyPyGuid.pyprojtest" />
Expand Down
9 changes: 9 additions & 0 deletions tests/Paket.Tests/ProjectFile/OutputSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ let ``should maintain order when updating project file items`` () =
]
CollectionAssert.AreEqual(expected, actual)

[<Test>]
let ``should not fail on Compile Remove entry without Include or Update attribute`` () =
ensureDir ()
let projFile = ProjectFile.TryLoad("./ProjectFile/TestData/CompileRemoveOnly.csprojtest").Value
let cache = PackProcessCache.empty
projFile.GetCompileItems false cache
|> Seq.toList
|> shouldEqual []

[<Test>]
let ``should remove missing files that exist in the project`` () =
ensureDir ()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyName>TestPaket</AssemblyName>
<TargetFramework>netstandard1.4</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Remove="Excluded.cs" />
</ItemGroup>
</Project>