Skip to content

[wasm][CoreCLR] Unify packaged application launch arguments - #137503

Draft
pavelsavara wants to merge 4 commits into
mainfrom
pavelsavara/browser-coreclr-cli-arguments
Draft

pavelsavara wants to merge 4 commits into
mainfrom
pavelsavara/browser-coreclr-cli-arguments

Conversation

@pavelsavara

@pavelsavara pavelsavara commented Nov 13, 2026 •

Copy link
Copy Markdown
Member

Summary

Define a consistent launch-argument contract for SDK-produced CoreCLR WebAssembly applications across Node.js, JavaScript shells, Browser, and WASI. Separate .NET launch configuration from managed application arguments without retaining the historical Mono argument conventions.

Updated on November 24: merge current main through a9ffa6f8b33c in 085293591f7d. The supported implementation is CoreCLR-only. Mono is retired, unsupported, and not built; this PR does not add or preserve a Mono compatibility layer. Active Browser/WASI SDK and launcher code still resides under src/mono.

Restore the historical Node entry-script detection and runMainAndExit path, but do not restore resource discovery. The app still uses its SDK-generated embedded boot configuration or WASI bundle. There are no CoreRun source changes, no assembly-directory scanning, and no new general-purpose managed-assembly runner.

Behavior changes

Area Previous behavior New behavior
Direct Node execution The current CoreCLR dotnet.js exported/configured a builder but did not automatically invoke managed Main. Executing the packaged dotnet.js directly starts its configured entry assembly and propagates the managed exit code.
Importing the loader Application JavaScript controlled runtime creation and execution. Importing still does not start managed code. When the application subsequently creates/runs the runtime, launch inputs are read and applied.
dotnet run forwarding WasmAppHost reparsed SDK-forwarded application arguments as host options, and downstream parsing could consume literal separators. Generated run commands insert an internal host boundary; arguments after it are preserved and parsed only by the .NET launch grammar.
Launch configuration Engine, historical runtime, and application arguments had no uniform contract. Leading --dotnet-* options configure environment/runtime properties; the first ordinary argument or -- starts the opaque application argument tail.
Configuration precedence Node inherited environment values filled missing entries; packaged/builder values won. Node process.env overrides packaged/builder environment values; explicit launch assignments override process.env. Launch property/environment overrides are reapplied after config-loaded initializers.
Browser launch inputs WasmAppHost wrote runArgs.json into the output and also placed application arguments in the URL. A per-process same-origin endpoint supplies launch configuration with Cache-Control: no-store; its address is included in the printed application URL. No per-run configuration file is written.
Browser application arguments Query argument consumption depended on an explicit builder call. The CoreCLR builder consumes launch arguments automatically. Repeated arg= values remain literal application arguments, including on a published app without a development endpoint.
CoreCLR WASI launch The launcher used the legacy module/entry layout. Start the SDK-linked wasihost in managed/corerun with the packaged entry assembly and required engine defaults. Use the supported CoreCLR layout directly, without runtime-flavor metadata, detection, or Mono fallback paths.
WASI runtime configuration Fresh main embeds generated runtime configuration in the per-app native host. Retain that embedded configuration, but add launch properties first and skip embedded duplicates so explicit overrides win. Do not restore runtimeconfig.bin loading.
Browser test URLs Combining launch and additional query parameters dropped query parameters embedded in BrowserPath, breaking the cache-seeding tests. Preserve all three query sources, encoded values, repeated/empty arguments, and fragments without duplicating an inherited base query.
Engine invocation PATH resolution was checked, but the unresolved executable name was launched. Launch the resolved executable path. Register the existing JavaScriptCore and SpiderMonkey handlers as well as Node/V8.

These are intentional behavioral changes in the active CoreCLR hosting and SDK plumbing. The latest merge removes this PR's WASI runtime-flavor task input, generated flavor metadata, and Mono single-file/legacy-module fallback paths. WasiAppBuilder.cs and WasiApp.targets no longer have PR-specific changes relative to main; no Mono runtime sources are changed.

Detailed usage

Common grammar

[--dotnet-env=NAME=VALUE]
[--dotnet-runtime-property=NAME=JSON_SCALAR]
[--dotnet-help]
[--]
[application arguments]
  • Only leading --dotnet-* options are interpreted.
  • The first ordinary argument begins the application argument tail; options after that point are not reparsed.
  • An explicit -- ends .NET launch-option parsing. Further -- tokens are ordinary application arguments.
  • Preserve argument order, empty strings, spaces, Unicode, leading dashes, and embedded =.
  • Environment values are strings. Split assignments at the first = after the name; an empty value is permitted.
  • Runtime-property values are JSON strings, finite numbers, or booleans. Reject null, objects, arrays, invalid JSON, and host-owned properties such as the assembly-search list or host contract.
  • Repeated assignments use the last value.
  • Unknown namespaced options and malformed assignments fail before managed startup.
  • --dotnet-help prints launcher usage without running managed Main; ordinary --help belongs to the application.
  • Overrides cannot restore code or features removed by trimming or disabled at build time.

Node.js: packaged application

Run from the published app's wwwroot directory, adjusting the path for the app's output layout:

node .\_framework\dotnet.js hello --verbose
node .\_framework\dotnet.js --dotnet-env=APP_MODE=test --dotnet-runtime-property=System.Globalization.Invariant=true -- --input data.txt
node .\_framework\dotnet.js '--dotnet-env=GREETING=hello world' '--dotnet-runtime-property=MyApp.Mode="fast"' -- input.txt
node .\_framework\dotnet.js --dotnet-help

The second command delivers ["--input", "data.txt"] to managed Main. The application and its dependencies are selected by the embedded boot configuration, not by probing the filesystem for assemblies.

An application argument that looks like a launcher option must be escaped with the boundary:

node .\_framework\dotnet.js -- --dotnet-env=literal -- ""

Managed arguments: ["--dotnet-env=literal", "--", ""].

dotnet run: same application contract

dotnet run -- hello --verbose
dotnet run -- --dotnet-env=APP_MODE=test --dotnet-runtime-property=System.Globalization.Invariant=true -- --input data.txt
dotnet run -- -- --dotnet-env=literal -- ""
dotnet run -- --dotnet-help

The first -- belongs to the .NET SDK and is consumed there. The optional second boundary belongs to the .NET application launcher. WasmAppHost's own internal boundary is generated by the build targets and is not something users need to supply.

Choose a configured host independently of application arguments:

dotnet run -p:WasmHostArguments=--host=node -- hello
dotnet run -p:WasmHostArguments=--host=browser -- --dotnet-env=APP_MODE=test -- hello

Here node and browser are names in wasmHostProperties.perHostConfig, not new SDK switches. --debug and --host=... in the application tail are application arguments, not WasmAppHost controls.

Engine flags and custom JavaScript startup

Engine options remain before the engine's entry script:

node --enable-source-maps .\_framework\dotnet.js --dotnet-env=APP_MODE=test -- hello

For dotnet run, use the host configuration's host-args, or the existing WasmHostArguments / --extra-host-arg mechanism. Engine switches are not added to the shared .NET launch grammar.

Applications requiring JavaScript setup still import the builder:

import { dotnet } from "./_framework/dotnet.js";

await dotnet
    .withEnvironmentVariable("APP_MODE", "builder-default")
    .runMainAndExit();
node .\main.mjs --dotnet-env=APP_MODE=launch-override -- hello

Importing alone does not run Main. The explicit launch value wins over the builder default. JavaScript shells consume scriptArgs or arguments using the same launch grammar; V8 was exercised through a custom ES module bootstrap rather than an automatically detected shell entry point. This draft restores automatic direct-entry execution for Node, not a universal shell self-starter.

Browser

The Browser host uses the same dotnet run -- ... grammar. Open the printed application URL, preserving its dotnet-launch parameter. The loader fetches that same-origin launch configuration before starting the runtime. CLI environment/runtime-property overrides win over packaged defaults, builder configuration, and config-loaded initializers.

The development server's inherited environment is not forwarded wholesale. In particular, do not assume SDK dotnet run -e NAME=VALUE reaches the Browser guest; use --dotnet-env=NAME=VALUE for this portable contract.

Published apps without dotnet-launch do not make an extra launch-configuration request. Their repeated ?arg=...&arg=... parameters are literal application arguments, not .NET launcher switches. Explicit arg= values take precedence over the application argument array in the launch payload.

WASI

From the SDK-generated CoreCLR WASI bundle directory:

wasmtime run -W exceptions=y -S http --dir . --env CORE_ROOT=/managed .\managed\corerun managed/MyApp.dll --dotnet-env=APP_MODE=test --dotnet-runtime-property=System.Globalization.Invariant=true -- hello

managed/corerun is the SDK's per-app linked wasihost, not the CoreRun development runner. The assembly argument is part of the existing packaged WASI layout; it does not introduce assembly discovery.

From the project directory:

dotnet run -- --dotnet-env=APP_MODE=test --dotnet-runtime-property=System.Globalization.Invariant=true -- hello

WasmAppHost supplies the packaged host/assembly arguments and the CoreCLR engine defaults. Wasmtime flags still belong before the module filename.

Runtime properties generated from the project are compiled into the per-app WASI host. For example, a packaged MyApp.Mode value remains the default with no override; passing '--dotnet-runtime-property=MyApp.Mode="launch"' overrides it for that invocation. No runtime-flavor field or runtimeconfig.bin is needed.

Implementation and migration notes

  • Restore selfHostNodeJS / isNodeHosted from the historical loader design without findResources.
  • Introduce matching parsers in the CoreCLR loader, WasmAppHost, and native WASI host.
  • Remove obsolete runArgs.json writing and the unused host-side runtime-argument property. Replace legacy Mono option strings with environment variables or supported CoreCLR runtime configuration properties.
  • Move actual WasmAppHost controls to WasmHostArguments or host configuration; application --help, --debug, and --host no longer configure the outer launcher.
  • Move application arguments resembling --dotnet-* after an explicit --.
  • Account for the new Node environment precedence when previously relying on builder/packaged values overriding inherited environment variables.
  • Keep Browser development URLs intact so launch inputs reach the guest.
  • Include two directly encountered WASI launch blockers: avoid appending the RID twice when computing the bundle working directory, and use Windows response-file quoting for the per-app native link.
  • Follow main's current embedded WASI runtime configuration instead of bringing back the old binary-file reader. Explicit launch values take precedence over generated defaults.
  • Remove the PR's Mono-related runtime-flavor metadata/task changes and compatibility branches. Remaining changes under src/mono are active CoreCLR SDK, launcher, documentation, and test code; there is no attempt to build or support the retired runtime.
  • No new public .NET library API is added. CLI semantics, precedence, shared host changes, and Browser development startup are the main review/compatibility considerations.

Validation

Latest merge validation (November 24)

Validated the merged 085293591f7d source locally on Windows, CoreCLR Debug. Browser and WASI builds were serialized in the same worktree. No Mono build or test was attempted.

Commands below ran from the worktree root unless noted.

Command Result
.\build.cmd -bl -os browser -subset clr+libs+host -c Debug /p:RuntimeFlavor=CoreCLR /p:EnableHotReloadInRuntimeConfigDevFile=false Passed, 0 warnings/errors.
.\build.cmd -bl -os wasi -subset clr+libs+host -c Debug /p:RuntimeFlavor=CoreCLR /p:EnableHotReloadInRuntimeConfigDevFile=false Passed, 0 warnings/errors.
.\dotnet.cmd pack -bl:artifacts\log\cli-nov24-sdk-pack.binlog /p:TargetOS=browser /p:TargetArchitecture=wasm /p:Configuration=Debug /p:RuntimeFlavor=CoreCLR /p:EnableHotReloadInRuntimeConfigDevFile=false .\src\mono\nuget\Microsoft.NET.Sdk.WebAssembly.Pack\Microsoft.NET.Sdk.WebAssembly.Pack.pkgproj Passed; regenerated the specific SDK package to avoid stale host/target inputs.
.\dotnet.cmd build -bl:artifacts\log\cli-nov24-regressions-final.binlog /p:TargetOS=browser /p:TargetArchitecture=wasm /p:Configuration=Debug /p:RuntimeFlavor=CoreCLR /p:EnableHotReloadInRuntimeConfigDevFile=false /p:InstallChromeForTests=false /p:TestUsingWorkloads=false /p:InstallWorkloadForTesting=false /p:XUnitClassName=Wasm.Build.Tests.MainWithArgsTests /t:Test .\src\mono\wasm\Wasm.Build.Tests Passed: 17 tests, 0 failed, 0 skipped. Includes real Node and Browser execution.
npx --no-install eslint --no-color --max-warnings=0 libs\Common\JavaScript\loader\launch.ts libs\Common\JavaScript\loader\bootstrap.ts libs\Common\JavaScript\loader\dotnet.ts libs\Common\JavaScript\loader\host-builder.ts libs\Common\JavaScript\loader\run.ts libs\Common\JavaScript\host\index.ts (from src\native) Passed.
git diff upstream/main HEAD --check Passed for the PR delta.

The 17-test run covers direct Node startup/exit, no-argument startup, import-only behavior, custom JS startup, SDK forwarding, exact empty/Unicode/space/=/separator arguments, environment/property precedence, duplicate assignments, invalid options, help, Browser launch endpoint/cache headers, and the published Browser path without an extra launch request. Five focused URL cases cover the previous cache-seeding regression; the real Browser run additionally asserts that the launch URL, BrowserPath, and extra query parameters all survive.

A temporary in-tree SDK-created WASI app was published with:

.\dotnet.cmd publish -bl:artifacts\log\cli-nov24-wasi-app.binlog /p:TargetOS=wasi /p:TargetArchitecture=wasm /p:Configuration=Debug /p:RuntimeFlavor=CoreCLR .\artifacts\tmp\cli-coreclr-merge\CliCoreClrMerge.csproj

Result: passed. Actual dotnet run --no-build -c Debug -p:TargetOS=wasi -p:TargetArchitecture=wasm -p:RuntimeFlavor=CoreCLR -- ... checks then passed both with no launch overrides and with repeated string-property overrides, a boolean override, and an environment assignment. They verified:

  • Embedded Cli.Property=packaged / Cli.Flag=false defaults remain intact without overrides.
  • Launch values replace the embedded defaults and the last assignment wins.
  • Empty arguments, spaces, literal --, namespaced-looking application arguments, and Unicode arrive exactly.
  • The managed app's exit code 42 is preserved.
  • No generated runtime-flavor metadata and no runtimeconfig.bin are required.

The temporary app was removed after validation.

The first local test attempt found missing .NET 12 host frameworks in the older constructed test SDK. Installed only the missing .NET/ASP.NET frameworks into that isolated SDK, then selected the already-restored current XHarness through the supported process-local XHARNESS_CLI_PATH setting. The final 17-test run passed; no user or machine environment settings were changed.

Not rerun for this merge: JavaScriptCore, SpiderMonkey, V8, Linux/macOS, Release, full suites, or the Blazor asset-caching class. The latter was previously blocked locally by NuGet audit errors in its pre-existing server dependency; the November 13 CI results did confirm both formerly failing caching methods pass on Windows and Linux after the URL fix. JavaScriptCore/SpiderMonkey handler registration is compiled but not runtime-validated.

Earlier validation

The original direct-Node regression was observed against the baseline: the loader exited 0 without running the app instead of returning the app's 42. Three of the new URL cases also failed before the query-composition fix.

Earlier iterations passed a focused Chrome JS-interop library smoke test, 16 appsettings tests after the November 6 merge, and real V8/Wasmtime launches with exact argv/environment/property/exit-code assertions. V8 used the repository's existing test-only crypto shim and a short path to avoid the installed engine's Windows path-length limitation. These historical checks are not claimed as rerun on the latest merge.

An exploratory in-process BenchmarkDotNet run measured the managed parser at approximately 38 ns / 208 B for no arguments and 752 ns / 1,192 B for one environment plus one runtime-property override. Timing confidence intervals were wide; these are absolute parser costs, not a baseline comparison or an end-to-end startup-performance claim.

Repository migration

Replaces dotnet/runtime#137002. Continue review and publication on dotnet/runtime branch pavelsavara/browser-coreclr-cli-arguments, not the original fork branch. The branch was initially copied at e5da3de3d36; the latest merge/cleanup is 085293591f7d.

Resolves #88760

Note

This pull request and its description were generated with GitHub Copilot.

pavelsavara and others added 3 commits November 5, 2026 08:26
Separate .NET environment and runtime-property overrides from application
arguments across Node, Browser, JavaScript shells, and WASI. Restore the
manifest-backed Node self-starter without assembly discovery, preserve
argument boundaries, and use transient Browser launch configuration.

Fix the SDK WASI host layout and Windows linking paths needed to exercise
the same contract. Add focused parser and real packaged-app regressions.

Co-authored-by: Copilot <[email protected]>
Preserve upstream's appsettings byte/file loading and the packaged-app
launch argument overrides and Node self-starter.

Co-authored-by: Copilot <[email protected]>
Combine the launch URL, browser path, and additional query parameters
without dropping asset selection or duplicating inherited queries.
Cover query escaping, fragments, repeated arguments, and actual browser
navigation alongside the packaged CLI regressions.

Co-authored-by: Copilot <[email protected]>
@pavelsavara pavelsavara added this to the 12.0.0 milestone Nov 13, 2026
@pavelsavara pavelsavara added arch-wasm WebAssembly architecture area-Host labels Nov 13, 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.

@azure-pipelines

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

Adapt WASI launch overrides to the embedded runtime configuration from
upstream/main. Keep host and explicit launch properties ahead of embedded
defaults when initializing CoreCLR.

Remove the PR's runtime-flavor metadata and Mono compatibility paths.
Use the supported CoreCLR WASI bundle layout directly without restoring
or extending the retired Mono runtime.

Co-authored-by: Copilot <[email protected]>

This branch has not been deployed

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

Labels

arch-wasm WebAssembly architecture area-Host

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[wasm] Host should separate arguments for engine, mono and application

1 participant