How do I use Mono WebAssembly to run a simple .NET method in browser?

前端 未结 1 1859
长发绾君心
长发绾君心 2021-02-15 08:05

Let\'s say I have a .NET dll file on the server, that has this simple class:

public static class C {
    public static int         


        
1条回答
  •  忘掉有多难
    2021-02-15 08:52

    Here's what I found.

    Obtain Mono WASM

    • The steps are described here: docs/getting-started/obtain-wasm-sdk.md
    • Short summary: you have to download and unpack a build from Jenkins

    Let's call the unpacked folder WASM-SDK.

    Note: you can skip following steps if you run packager.exe as described in Mono docs, but I want to describe the manual approach here for better understanding.

    Prepare .NET dlls

    Put the following dlls under your site root (lets say under managed folder):

    • Main dll that contains class C, let's call it app.dll
    • BCL dependencies, in this case you only need:
      1. WASM-SDK\wasm-bcl\wasm\mscorlib.dll
      2. WASM-SDK\wasm-bcl\wasm\Facades\netstandard.dll
      3. WASM-SDK\framework\WebAssembly.Bindings.dll

    Prepare Web files

    1. Copy mono.js and mono.wasm from WASM-SDK\release under your site root
    2. Register your Module and import mono.js:
    
    
    1. If using IIS, make sure that there is a application/wasm mime type register for the .wasm extension.

    All done

    Now once you open your HTML you should see C.Add: 3 logged in the browser console.

    0 讨论(0)
提交回复
热议问题