Skip to content

[wasm] Fix MSB4057 publishing CoreCLR browser-wasm apps#131372

Open
lewing wants to merge 1 commit into
dotnet:mainfrom
lewing:lewing-stunning-eureka
Open

[wasm] Fix MSB4057 publishing CoreCLR browser-wasm apps#131372
lewing wants to merge 1 commit into
dotnet:mainfrom
lewing:lewing-stunning-eureka

Conversation

@lewing

@lewing lewing commented Jul 25, 2026

Copy link
Copy Markdown
Member

Publishing a browser-wasm app with the experimental CoreCLR wasm SDK fails with:

error MSB4057: The target "_WasmBuildAppCore" does not exist in the project.
  (BrowserWasmApp.CoreCLR.targets(216))

Why

Microsoft.NET.Runtime.WebAssembly.Sdk/Sdk/Sdk.targets.in imports BrowserWasmApp.props unconditionally, which pulls in WasmApp.Common.props, and only then picks the flavor-specific targets file (BrowserWasmApp.CoreCLR.targets when UseMonoRuntime == 'false').

WasmApp.Common.props defaulted WasmNestedPublishAppDependsOn to _WasmBuildAppCore, which is defined in WasmApp.Common.targets. The CoreCLR path never imports that file (it defines its own _CoreCLRWasmBuildAppCore), so the CoreCLR WasmNestedPublishApp target inherited a dependency on a target that does not exist in its import chain.

Approach

Guard the Mono-only target lists in WasmApp.Common.props with Condition="'$(UseMonoRuntime)' != 'false'". The flavor decision happens two lines after that import in Sdk.targets.in, so the property is already set when the props are evaluated.

The CoreCLR path now starts from an empty list and relies on its own _CoreCLRWasmBuildAppCore, which was already listed explicitly in its DependsOnTargets. Contributions that prepend to the property still compose correctly, so nothing is lost:

  • _GatherWasmFilesToPublish (Microsoft.NET.Sdk.WebAssembly.Browser.targets)
  • PrepareForWasmBuildApp (eng/testing/tests.browser.targets)

Notes

  • The Mono path is unchanged: verified by evaluating the real import chain with msbuild, UseMonoRuntime=true still yields _WasmBuildAppCore for both WasmBuildAppDependsOn and WasmNestedPublishAppDependsOn, while UseMonoRuntime=false yields empty lists with TargetArchitecture=wasm still set.
  • In-tree browser CoreCLR builds were already unaffected, since WasmApp.InTree.props imports BrowserWasmApp.props only for Mono. This only bites consumers of the packaged SDK.
  • WASI is not impacted: its CoreCLR path (WasiApp.CoreCLR.targets) defines no nested-publish target.

Note

This change was drafted with GitHub Copilot.

The packaged WebAssembly SDK (Microsoft.NET.Runtime.WebAssembly.Sdk/Sdk/Sdk.targets.in)
imports BrowserWasmApp.props unconditionally, which pulls in WasmApp.Common.props, and
then selects BrowserWasmApp.CoreCLR.targets when UseMonoRuntime is false. Those props
defaulted WasmNestedPublishAppDependsOn to _WasmBuildAppCore, a target defined in
WasmApp.Common.targets, which the CoreCLR path never imports. Publishing a CoreCLR
browser-wasm app therefore failed with:

  MSB4057: The target "_WasmBuildAppCore" does not exist in the project.

Guard the Mono-only target lists on UseMonoRuntime != 'false' so the CoreCLR path starts
from an empty list and uses its own _CoreCLRWasmBuildAppCore, while contributions that
prepend to the property (the WebAssembly SDK's _GatherWasmFilesToPublish and the test
targets' PrepareForWasmBuildApp) still compose correctly.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: b49e36e8-8a37-48ef-b7e8-54ac6443ea19
Copilot AI review requested due to automatic review settings July 25, 2026 16:18
@lewing
lewing requested review from akoeplinger and maraf as code owners July 25, 2026 16:18
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes a build/publish failure for CoreCLR-based browser-wasm apps caused by WasmApp.Common.props seeding Wasm*DependsOn properties with Mono-only target names that aren’t imported/defined in the CoreCLR flavor’s targets chain.

Changes:

  • Split WasmApp.Common.props so TargetArchitecture=wasm remains unconditional, while the WasmBuildAppDependsOn / _WasmBuildAppCoreDependsOn / WasmNestedPublishAppDependsOn defaults are only set when $(UseMonoRuntime) != 'false'.
  • Add an explanatory comment documenting why these lists must not be seeded for CoreCLR.

@lewing lewing added arch-wasm WebAssembly architecture os-browser Browser variant of arch-wasm labels Jul 25, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to 'arch-wasm': @lewing, @pavelsavara
See info in area-owners.md if you want to be subscribed.

@lewing

lewing commented Jul 25, 2026

Copy link
Copy Markdown
Member Author

@maraf there was indeed a problem

(see Microsoft.NET.Runtime.WebAssembly.Sdk/Sdk/Sdk.targets.in), and it defines its own
equivalents. Seeding the Mono names there would make its WasmNestedPublishApp target
depend on the non-existent _WasmBuildAppCore, failing the build with MSB4057. -->
<PropertyGroup Condition="'$(UseMonoRuntime)' != 'false'">

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe we should condition the import of BrowserWasmApp.props or WasmApp.Common.props in the workload pack.

My initial goal with CoreCLR targets was to a create completely separate CoreCLR-only set of targets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-Build-mono os-browser Browser variant of arch-wasm

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants