Skip to content

[wasm] Restore net472 multi-targeting for WasmAppBuilder; fix Type.IsFunctionPointer compile break#125373

Merged
maraf merged 6 commits intomainfrom
copilot/revert-multi-targeting-wasmappbuilder
Mar 13, 2026
Merged

[wasm] Restore net472 multi-targeting for WasmAppBuilder; fix Type.IsFunctionPointer compile break#125373
maraf merged 6 commits intomainfrom
copilot/revert-multi-targeting-wasmappbuilder

Conversation

Copy link
Contributor

Copilot AI commented Mar 10, 2026

WasmAppBuilder was changed to single-target ($(NetCoreAppToolCurrent) only), breaking net472 builds needed for full-framework MSBuild hosts (Visual Studio). Type.IsFunctionPointer — a .NET 7+ API — was also used directly in the CoreCLR generator, causing a compile error on net472.

Changes

WasmAppBuilder.csproj — restore multi-targeting to match the pre-#122007 structure (with the sole exception of the todo-pinvoke-helpers.cpp → callhelpers-reverse.cpp rename already present on main):

  • <TargetFramework><TargetFrameworks>$(NetCoreAppToolCurrent);$(NetFrameworkToolCurrent)
  • Restore <Nullable>enable</Nullable>
  • Restore per-TFM NoWarn conditions: CA1050/CS8604/CS8602 suppressed for .NETFramework; CA1050/CA1850 suppressed for non-.NETFramework (no unconditional NoWarn line)
  • Restore .NETFramework compile includes (IsExternalInit.cs — needed for init setters in PInvokeCollector.cs — and NullableAttributes.cs) with the original $(RepoRoot)src\libraries\System.Private.CoreLib/... path
  • Keep RuntimeFlavor == 'Mono' condition (uppercase, unchanged from main)
  • Split Microsoft.Build.Tasks.Core PackageDownloadAndReference into per-TFM entries (ref/net472 / ref/net8.0) with IsTargetFrameworkCompatible guards (restored from pre-[wasm][coreclr] 2nd part of call helpers generator, reverse calls #122007)
  • Restore GetFilesToPackage with explicit $(OutputPath)$(NetCoreAppToolCurrent)\... paths and $(NetFrameworkToolCurrent)\* dependent-assembly glob
  • Restore UsingTask pointing to $(OutputPath)$(NetCoreAppToolCurrent)\WasmAppBuilder.dll without Runtime="NET"

coreclr/PInvokeTableGenerator.cs — replace direct Type.IsFunctionPointer usage with a reflection-based helper (mirrors the existing helper in mono/PInvokeTableGenerator.cs):

public static bool IsFunctionPointer(Type type)
{
    object? bIsFunctionPointer = type.GetType().GetProperty("IsFunctionPointer")?.GetValue(type);
    return (bIsFunctionPointer is bool b) && b;
}

Both PickCTypeNameForUnknownType and IsBlittableUncached now call IsFunctionPointer(t) instead of t.IsFunctionPointer.

coreclr/SignatureMapper.cs — same: replace t.IsFunctionPointer with PInvokeTableGenerator.IsFunctionPointer(t).

Runtime behavior on net10.0 is unchanged — reflection resolves to the same property.

Original prompt

Create a PR in dotnet/runtime that reverts the removal of multi-targeting from the WasmAppBuilder task project and fixes net472 compilation issues around PInvokeTableGenerator.IsFunctionPointer.

Context:

  • The current src/tasks/WasmAppBuilder/WasmAppBuilder.csproj is single-targeting via <TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework>.
  • We need to restore the previous multi-targeting (likely via <TargetFrameworks>...), so that the task assembly can compile for net472 again.
  • There is also a compile break for net472 due to use of Type.IsFunctionPointer in the CoreCLR-flavor generator.

Required changes:

  1. Revert single-targeting in src/tasks/WasmAppBuilder/WasmAppBuilder.csproj back to multi-targeting.

    • Restore <TargetFrameworks> instead of <TargetFramework>.
    • Use the same TFMs as before the regression (determine by git history / blame / previous commits on that file). If unclear, prefer including net472 plus the existing $(NetCoreAppToolCurrent) (or the repo-standard property for the other TFM) to match prior behavior.
    • Ensure packaging target GetFilesToPackage still produces the expected output layout and includes all target outputs appropriately.
  2. Make src/tasks/WasmAppBuilder/coreclr/PInvokeTableGenerator.cs compile on net472.

    • Replace direct use of type.IsFunctionPointer with a reflection-based helper similar to the one in src/tasks/WasmAppBuilder/mono/PInvokeTableGenerator.cs:
      • public static bool IsFunctionPointer(Type type) that uses type.GetType().GetProperty("IsFunctionPointer")?.GetValue(type).
    • Update the blittable checks / mapping code that currently references type.IsFunctionPointer to use the helper.
    • Keep runtime behavior equivalent on newer TFMs.
  3. Add/adjust any conditional compilation if necessary so the code continues to build for non-net472 TFMs without warnings.

  4. Add or update tests if there are existing build/test projects that cover the generator; at minimum, ensure the project builds for all target frameworks.

Notes:

  • The PR should be minimal and focused: restore multi-targeting and fix the IsFunctionPointer net472 compile issue.
  • Please include a clear PR title and description explaining why multi-targeting is needed and what was reverted.

Relevant files:

  • src/tasks/WasmAppBuilder/WasmAppBuilder.csproj
  • src/tasks/WasmAppBuilder/coreclr/PInvokeTableGenerator.cs
  • (reference for helper) src/tasks/WasmAppBuilder/mono/PInvokeTableGenerator.cs

Reference PR for nearby changes:

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Revert the remove of multi-targeting from WasmAppBuilder.csproj

Assistant: I found the current WasmAppBuilder.csproj at:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>$(NetCoreAppToolCurrent)</TargetFramework>
    <NoWarn>$(NoWarn),CA1050,CA1850</NoWarn>
    <EnableSingleFileAnalyzer>false</EnableSingleFileAnalyzer>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
    <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
  </PropertyGroup>

…but with the tools available here I could not locate the specific prior commit/PR where multi-targeting (<TargetFrameworks>...) was removed, nor retrieve the previous file version/diff (the searches came back empty / incomplete, and the commit-diff attempt didn’t return a usable diff).

What I need from you to do the revert correctly

Please provide one of the following, and I can produce the exact patch (or open a PR if you ask):

  1. The commit SHA (or PR number) that removed multi-targeting from src/tasks/WasmAppBuilder/WasmAppBuilder.csproj, or
  2. A link to the “History” view of that file showing the change (copy/paste the commit link), or
  3. Tell me what the multi-targeting used to be (e.g. net8.0;net9.0 or $(NetCoreAppToolCurrent);$(NetCoreAppToolPrevious) etc).

Quick pointer

You can find it quickly via GitHub UI history:

  • src/tasks/WasmAppBuilder/WasmAppBuilder.csprojHistory → look for the commit that changed TargetFrameworks to TargetFramework.

Also note: the code-search results I got are limited and may be incomplete. If you want to dig via UI search, try:
https://github.com/dotnet/runtime/search?q=path%3Asrc%2Ftasks%2FWasmAppBuilder%2FWasmAppBuilder.csproj+TargetFrameworks&type=commits

Once you paste the commit/old TargetFrameworks line, I’ll generate the exact reverted WasmAppBuilder.csproj content.

User: There will also be a need to revert part around PInvokeTableGenerator.IsFunctionPointer to make the assembly compile for net472

Assistant: To make this compile for net472, the immediate problem area is that t...

This pull request was created from Copilot chat.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…ctionPointer compile issues

Co-authored-by: maraf <10020471+maraf@users.noreply.github.com>
Copilot AI changed the title [WIP] Revert removal of multi-targeting in WasmAppBuilder task [wasm] Restore multi-targeting in WasmAppBuilder.csproj; fix net472 IsFunctionPointer compile errors Mar 10, 2026
Copilot AI changed the title [wasm] Restore multi-targeting in WasmAppBuilder.csproj; fix net472 IsFunctionPointer compile errors [wasm] Restore net472 multi-targeting for WasmAppBuilder; fix Type.IsFunctionPointer compile break Mar 10, 2026
…edback

Co-authored-by: maraf <10020471+maraf@users.noreply.github.com>
Copy link
Member

@radekdoulik radekdoulik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, LGTM

@maraf maraf marked this pull request as ready for review March 12, 2026 18:22
@maraf maraf requested a review from akoeplinger as a code owner March 12, 2026 18:22
Copilot AI review requested due to automatic review settings March 12, 2026 18:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR restores net472 multi-targeting for the WasmAppBuilder task project that was inadvertently removed in PR #122007, and fixes a compile break caused by direct use of Type.IsFunctionPointer (a .NET 7+ API) in the CoreCLR PInvoke generator code.

Changes:

  • Restore <TargetFrameworks> to include both $(NetCoreAppToolCurrent) and $(NetFrameworkToolCurrent), along with per-TFM NoWarn conditions, .NETFramework compile includes, and packaging target adjustments.
  • Replace direct Type.IsFunctionPointer calls in coreclr/PInvokeTableGenerator.cs and coreclr/SignatureMapper.cs with a reflection-based helper, mirroring the existing pattern in mono/PInvokeTableGenerator.cs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
WasmAppBuilder.csproj Restore multi-targeting, nullable settings, per-TFM warning suppression, framework-specific compile includes, per-TFM PackageDownloadAndReference, packaging target, and UsingTask path
coreclr/PInvokeTableGenerator.cs Add reflection-based IsFunctionPointer helper; replace direct API calls
coreclr/SignatureMapper.cs Replace t.IsFunctionPointer with PInvokeTableGenerator.IsFunctionPointer(t)

You can also share your feedback on Copilot code review. Take the survey.

Co-authored-by: maraf <10020471+maraf@users.noreply.github.com>
Copilot AI requested a review from maraf March 12, 2026 18:35
@maraf maraf enabled auto-merge (squash) March 12, 2026 18:58
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@maraf maraf merged commit 12bcd5d into main Mar 13, 2026
37 of 39 checks passed
@maraf maraf deleted the copilot/revert-multi-targeting-wasmappbuilder branch March 13, 2026 00:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants