Using assemblies compiled from IL with .NET Core & Xamarin

后端 未结 2 930
粉色の甜心
粉色の甜心 2021-02-09 08:18

Updated with a solution that works for me. See the bottom of this question.

Context:
I needed a way to evaluate the size of a generic type for the p

2条回答
  •  猫巷女王i
    2021-02-09 09:03

    Ok, this is the result of my research (based on https://github.com/dotnet/corefx/tree/master/src/System.Runtime.CompilerServices.Unsafe and https://github.com/jvbsl/ILProj):

    global.json:

    {
      "msbuild-sdks": {
        "Microsoft.NET.Sdk.IL": "3.0.0-preview-27318-01"
      }
    }
    

    ILProj\ILProj.ilproj:

    
    
        
            netstandard2.0
            3.0.0-preview-27318-01
            include\netstandard
            include\netstandard
            include\netcoreapp
            include\netcoreapp
            $(IlasmFlags) -INCLUDE=$(IncludePath)
        
    
    
    

    ILProj\include\netstandard\coreassembly.h:

    #define CORE_ASSEMBLY "System.Runtime"
    
    // Metadata version: v4.0.30319
    .assembly extern CORE_ASSEMBLY
    {
      .publickeytoken = ( B0 3F 5F 7F 11 D5 0A 3A )
      .ver 4:0:0:0
    }
    
    

    ILProj\Class.il

    #include "coreassembly.h"
    
    .assembly ILProj
    {
      .ver 1:0:0:0
    }
    
    .module ILProj.dll
    
    .class public abstract auto ansi sealed beforefieldinit ILProj.Class
      extends [CORE_ASSEMBLY]System.Object
    {
      .method public hidebysig static int32 Square(int32 a) cil managed
      {
        .maxstack 2
        ldarg.0
        dup
        mul
        ret
      }
    }
    

    If you have difficulties to put it all together, then look at the example here: https://github.com/Konard/ILProj

提交回复
热议问题