Repository navigation
Open
Labels
Milestone
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
| private void UpdateConsoleMainJs() | |
| { | |
| string mainJsPath = Path.Combine(_projectDir!, "main.mjs"); | |
| string mainJsContent = File.ReadAllText(mainJsPath); | |
| mainJsContent = mainJsContent | |
| .Replace(".create()", ".withConsoleForwarding().create()") | |
| .Replace("[\"dotnet\", \"is\", \"great!\"]", "(await import(/* webpackIgnore: true */\"process\")).argv.slice(2)"); | |
| File.WriteAllText(mainJsPath, mainJsContent); | |
| } |
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
Activity
pavelsavara commentedon Sep 26, 2022
we could have simpler
await dotnet.run()instead ofawait runMainAndExitmaraf commentedon Sep 27, 2022
Why do we have
dotnet.runwhat implicitly reads main assembly and arguments, butrunMainAndExitrequires to pass them explicitly?Using
dotnet.run()afterconst runtime = dotnet.create()seems like "a break in code flow".pavelsavara commentedon Sep 27, 2022
Because it's a lower level API which is not part of the builder pattern.
That's OK :)
WBT: workaround for #76201
Revert "WBT: workaround for #76201"
WBT: workaround for dotnet#76201
pavelsavara commentedon Sep 30, 2022
I believe this was fixed by #76182 and #76373
Is that right @radical @maraf ?
maraf commentedon Sep 30, 2022
Partially. It passes command line args for the console template.
9 remaining items
lewing commentedon Feb 21, 2024
cc @richlander
lewing commentedon Feb 21, 2024
What area owns template argument parsing and where should this be redirected?
maraf commentedon Feb 21, 2024
I think this is all WasmAppHost related
lewing commentedon Feb 21, 2024
I think the app host doesn't get all the information it needs, but I hope I'm wrong