Skip to content

Commit 45046d7

Browse files
committed
Fixed NuGet packaging of DesignTime DLL for F# provider
Added MSBuild target to ensure DesignTime DLL is included in NuGet package, working around F# SDK limitations with ProjectReference-based providers. Removed obsolete target for cleaning NuGet pack input and updated conditions for consistency.
1 parent d8aba70 commit 45046d7

1 file changed

Lines changed: 50 additions & 19 deletions

File tree

src/FSharp.Data.GraphQL.Client/FSharp.Data.GraphQL.Client.fsproj

Lines changed: 50 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,57 @@
44
<OutputType>Library</OutputType>
55
<TargetFramework>netstandard2.0</TargetFramework>
66
<GenerateDocumentationFile>true</GenerateDocumentationFile>
7-
<FSharpToolsDirectory>typeproviders</FSharpToolsDirectory>
8-
<PackagePath>typeproviders</PackagePath>
97

108
<Description>FSharp implementation of Facebook GraphQL query language (Client)</Description>
11-
<NoWarn>$(NoWarn);NU5100</NoWarn>
129
</PropertyGroup>
1310

11+
<!-- Include the DesignTime DLL into the package alongside the runtime DLL.
12+
The F# compiler searches for the DesignTime DLL in the same directory as the runtime DLL.
13+
14+
The standard SDK mechanism (PackageFSharpDesignTimeTools via IsFSharpDesignTimeProvider) does not
15+
work here for the "runtime project references designtime via ProjectReference" pattern.
16+
17+
Root cause: dotnet pack invokes the project a second time with BuildProjectReferences=false
18+
to collect package content (_GetTfmSpecificContentForPackage). This flag prevents MSBuild from
19+
running ResolveProjectReferences, so _ResolvedProjectReferencePaths is empty in that inner context.
20+
PackageFSharpDesignTimeTools reads _ResolvedProjectReferencePaths to find the DesignTime DLL —
21+
and finds nothing.
22+
23+
This is a known MSBuild/F# SDK limitation. Relevant references:
24+
- dotnet/fsharp#18924 PackageFSharpDesignTimeTools target interacts unpredictably with the build
25+
https://github.com/dotnet/fsharp/issues/18924
26+
- dotnet/fsharp#18929 Fix early/unconditional execution of PackageFSharpDesignTimeTools (merged
27+
Oct 2025, SDK 10.0.301) — fixes the direct IsFSharpDesignTimeProvider=true
28+
case but explicitly does NOT fix the ProjectReference case due to MSBuild
29+
evaluation-phase constraints
30+
https://github.com/dotnet/fsharp/pull/18929
31+
- dotnet/fsharp#12320 NETSDK1085 when packing with `no-build`
32+
https://github.com/dotnet/fsharp/issues/12320
33+
34+
Workaround: hook into TargetsForTfmSpecificContentInPackage at evaluation time (PropertyGroup),
35+
then use GetTargetPath to resolve the DesignTime DLL path without triggering a build, and inject
36+
it directly as a TfmSpecificPackageFile. -->
37+
<PropertyGroup Condition="'$(IsNuGet)' != ''">
38+
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);_IncludeDesignTimeDllInPackage</TargetsForTfmSpecificContentInPackage>
39+
</PropertyGroup>
40+
41+
<Target Name="_IncludeDesignTimeDllInPackage" Condition="'$(IsNuGet)' != ''">
42+
<ItemGroup>
43+
<_DesignTimeProjectRef Include="@(ProjectReference)"
44+
Condition="'%(ProjectReference.IsFSharpDesignTimeProvider)' == 'true'" />
45+
</ItemGroup>
46+
<MSBuild Projects="@(_DesignTimeProjectRef)"
47+
Targets="GetTargetPath"
48+
Properties="Configuration=$(Configuration);TargetFramework=$(TargetFramework)">
49+
<Output TaskParameter="TargetOutputs" ItemName="_DesignTimeDllPath" />
50+
</MSBuild>
51+
<ItemGroup>
52+
<TfmSpecificPackageFile Include="@(_DesignTimeDllPath)">
53+
<PackagePath>lib\$(TargetFramework)</PackagePath>
54+
</TfmSpecificPackageFile>
55+
</ItemGroup>
56+
</Target>
57+
1458
<ItemGroup>
1559
<PackageReference Update="FSharp.Core" VersionOverride="$(FSharpCoreVersion)">
1660
<PrivateAssets>all</PrivateAssets>
@@ -36,25 +80,12 @@
3680
<Compile Include="GraphQLProvider.Runtime.fs" />
3781
</ItemGroup>
3882

39-
<Target Name="RemoveUnnecessaryNuGetPackInput" BeforeTargets="GenerateNuspec">
40-
<ItemGroup>
41-
<FSharpCoreNuGetPackInput Include="@(NuGetPackInput)" Condition="$([System.String]::Copy( %(FullPath) ).EndsWith('FSharp.Core.resources.dll'))" />
42-
<PdbNuGetPackInput Include="@(NuGetPackInput)" Condition="$([System.String]::Copy( %(FullPath) ).Contains('DesignTime')) And ('%(Extension)' == '.pdb' OR '%(Extension)' == '.xml')" />
43-
</ItemGroup>
44-
<ItemGroup>
45-
<NuGetPackInput Remove="@(FSharpCoreNuGetPackInput)" />
46-
<NuGetPackInput Remove="@(PdbNuGetPackInput)" />
47-
<_PackageFiles Remove="@(FSharpCoreNuGetPackInput)" />
48-
<_PackageFiles Remove="@(PdbNuGetPackInput)" />
49-
</ItemGroup>
50-
</Target>
51-
5283
<ItemGroup>
53-
<ProjectReference Condition="$(IsNuGet) != ''" Include="..\FSharp.Data.GraphQL.Client.DesignTime\FSharp.Data.GraphQL.Client.DesignTime.fsproj">
84+
<ProjectReference Condition="'$(IsNuGet)' != ''" Include="..\FSharp.Data.GraphQL.Client.DesignTime\FSharp.Data.GraphQL.Client.DesignTime.fsproj">
5485
<IsFSharpDesignTimeProvider>true</IsFSharpDesignTimeProvider>
5586
<PrivateAssets>all</PrivateAssets>
5687
</ProjectReference>
57-
<PackageReference Condition="$(IsNuGet) != ''" Include="FSharp.Data.GraphQL.Shared" VersionOverride="$(Version)" />
58-
<ProjectReference Condition="$(IsNuGet) == ''" Include="..\FSharp.Data.GraphQL.Shared\FSharp.Data.GraphQL.Shared.fsproj" />
88+
<PackageReference Condition="'$(IsNuGet)' != ''" Include="FSharp.Data.GraphQL.Shared" VersionOverride="$(Version)" />
89+
<ProjectReference Condition="'$(IsNuGet)' == ''" Include="..\FSharp.Data.GraphQL.Shared\FSharp.Data.GraphQL.Shared.fsproj" />
5990
</ItemGroup>
6091
</Project>

0 commit comments

Comments
 (0)