fsprojects / fsprojects/Paket

Wrong import in non SDK-style managed projects for native and managed targets

Open
#4,073 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
F#
Stars
2.1k
Forks
528
Avg merge
1d 12m
Merged PRs (30d)
54

Description

Description

We are using packages with native binaries as well as header and library files. For native projects, our packages are supposed to include headers/lib and copy binaries to output. For managed projects (this includes older non SDK-style projects), we just want to copy binaries to the output.

Thus, the build folder in our package structure is as follows:

  • build
    • native
      • MyPackage.targets
    • netstandard2.0
      • MyPackage.targets

However, build\netstandard2.0\MyPackage.targets is not properly imported and it will use the native one instead.

Repro steps

Create a package as described above and install it using paket into a managed, non SDK-style project, for example targeting .NET 4.7.2.

Expected behavior

An <Import> tag is written importing build\netstandard2.0\MyPackage.targets.

Actual behavior

The <Import> tag will point to build\native\MyPackage.targets.

Cause

The <Choose> element written will look like this:

<Choose>
    <When Condition="true">
      <PropertyGroup>
        <__paket__MyPackage_targets>native\MyPackage</__paket__MyPackage_targets>
      </PropertyGroup>
    </When>
    <When Condition="('$(TargetFrameworkIdentifier)' == '.NETFramework' And '$(TargetFrameworkVersion)' == 'v4.7.2') Or ($(TargetFrameworkIdentifier) == '.NETCoreApp' And $(TargetFrameworkVersion) == 'v5.0') Or ($(TargetFrameworkIdentifier) == '.NETStandard' And $(TargetFrameworkVersion) == 'v2.0')">
      <PropertyGroup>
        <__paket__MyPackage_targets>netstandard2.0\MyPackage</__paket__MyPackage_targets>
      </PropertyGroup>
    </When>
  </Choose>

Since the condition on the first <When> is true, the second one will never be evaluated (this is expected behavior as documented here) and the path will always point to the native targets file.

Suggested fix

Write the <When Condition="true"> element last so it is only hit if no other condition applies.

Known workarounds

Manually edit the project file to reflect the suggested fix.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating Paket's project-file generation entry point for the XML Choose/Import block described in the issue, then reproduce with a non-SDK-style .NET Framework 4.7.2 project. Verify that the unconditional native When element is emitted last and that the generated import selects build\netstandard2.0\MyPackage.targets.

Written by the indexing model from the issue text.

Assessment

Tech stack
fsharp
Domain
build-system
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.