Open
Description
If we print the command line args:
using System;
using System.Runtime.InteropServices.JavaScript;
Console.WriteLine("Hello, Console!");
Console.WriteLine ($"command line args: {string.Join(',', args)}");
return 0;
public partial class MyClass
{
[JSExport]
internal static string Greeting()
{
var text = $"Hello, World! Greetings from node version: {GetNodeVersion()}";
return text;
}
[JSImport("node.process.version", "main.mjs")]
internal static partial string GetNodeVersion();
}
.. and run:
$ dotnet run x y z
WasmAppHost --runtime-config /tmp/cc/bin/Debug/net7.0/browser-wasm/AppBundle/cc.runtimeconfig.json x y z
Running: node main.mjs x y z
Using working directory: /tmp/cc/bin/Debug/net7.0/browser-wasm/AppBundle
mono_wasm_runtime_ready fe00e07a-5519-4dfe-b35a-f867dbaf2e28
Hello, World! Greetings from node version: v14.18.2
Hello, Console!
command line args: dotnet,is,great!
The command line arguments x y z
were ignored, and instead we got dotnet,is,great
. And that's because the main.mjs
has:
await runMainAndExit(config.mainAssemblyName, ["dotnet", "is", "great!"]);
This doesn't get caught by Wasm.Build.Tests because the tests are explicitly patching the generated code
runtime/src/tests/BuildWasmApps/Wasm.Build.Tests/WasmTemplateTests.cs
Lines 48 to 58 in 4bd3ee5
And the same is done for the browser too.
We should instead:
- Pass the command line args for console, and browser to the app
- Automatically set console forwarding if runArgs has forward console set
- The tests should be updated to run the template exactly as it is generated. And a follow up test can patch it to print the arguments, and check that
cc @pavelsavara