将现有的C#代码编译为WebAssembly

c#

是否可以将现有的 C# 代码编译为 WebAssembly (.wasm),以便无需或几乎无需更改代码?

我必须为此使用 Blazor 还是其他可能性?

回答

是否可以将现有的 C# 代码编译为 WebAssembly (.wasm)

不,没有编译器(还)。但

以便无需或几乎无需更改代码?

这很简单,您可以简单地将 .net DLL(包)添加到您的项目中。
只要确保代码在浏览器中有意义,即没有线程,没有 I/O,除了 HttpClient 等。

我必须为此使用 Blazor 还是其他可能性?

目前只有 Blazor。

  • Well, there is Microsoft's NativeAOT (was CoreRT) https://github.com/dotnet/runtimelab/blob/feature/NativeAOT-LLVM/docs/workflow/building/coreclr/nativeaot.md . Its not an officially supported branch, the community contributes to it with help from Microsoft. It will compile some c# code to Wasm (using emscripten and the LLVM compiler). You can look at the HelloWasm.cs test bucket to get an idea of what should work : https://github.com/dotnet/runtimelab/blob/feature/NativeAOT-LLVM/src/tests/nativeaot/SmokeTests/HelloWasm/HelloWasm.cs

以上是将现有的C#代码编译为WebAssembly的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>