dotnet-webassembly icon indicating copy to clipboard operation
dotnet-webassembly copied to clipboard

Consider saving DLLs with Mono.Cecil

Open michaelkruglos opened this issue 5 years ago • 3 comments

Have you considered Mono.Cecil for assembly generation? It can write DLLs, which can later be used with .net core. If you copy the <appname>.runtimeconfig.json from any existing .net core app as <dllname>.runtimeconfig.json, you can run that dll with dotnet <dllname>.dll. There's no point in waiting for Microsoft to implement it. They mentioned it not being a must have for NET 5. In the mean-time Mono.Cecil does an excellent job and comes with the ability to optimize methods.

Examples:

michaelkruglos avatar Aug 22 '20 18:08 michaelkruglos

I won't personally do it but I'm planning to add extension points to the compilation process to enable this scenario. There's definitely interest, and I suspect someone might take this on.

My most pressing concern right now is to be able to compile complex real-world WASMs--being able to write DLLs is of no help to anyone if they don't work.

RyanLamansky avatar Aug 23 '20 20:08 RyanLamansky

Note that Mono.Cecil has several huge API differences, especially when it comes to resolving .NET Types. In XamlX compiler we have some kind of an abstraction for SRE and Mono.Cecil APIs that allows to access .NET type system and emit MSIL in a unified way, a full example that a emits a class can be found here.

It also comes with a sanity checking IL emitter proxy that checks basic things like stack balance at label instructions, unmarked labels, etc.

It's possible to extract said abstraction to a separate library if that would help.

kekekeks avatar Oct 15 '20 23:10 kekekeks

I have done some experiments with saving the generated assembly using Lokad.ILPack which does some magic to save the System.Reflection.Emit assemblies even on .NET Core, where the feature is directly missing. Should be as simple as follwing, but definitely needs more testing.

var gen = new Lokad.ILPack.AssemblyGenerator();
gen.GenerateAssembly(module.Assembly, "generated.dll");

yself avatar Nov 06 '20 10:11 yself