Cannot get types from .winmd file

前端 未结 3 1983
一向
一向 2021-01-20 08:19

I want to output the types in a .winmd file given its path. I copied a winmd file from my Windows 8 Developer Preview machine to my dev machine. I wrote a small test app (in

相关标签:
3条回答
  • 2021-01-20 09:05

    WinMDs are metadata only assemblies. Using ReflectionOnlyLoadFrom should do the trick.

    The following code works.

            var assembly = System.Reflection.Assembly.ReflectionOnlyLoadFrom(winmdPath);
    
    
            foreach (var type in assembly.GetTypes())
            {
                Console.WriteLine("type found name = " + type.Name);
            }
    
    0 讨论(0)
  • 2021-01-20 09:16

    While .winmd files use the ECMA 355 file format, they are NOT .Net assemblies, and it is highly unlikely that you'll be able to read the files using the .Net framework directly.

    If you use the version of ILDASM shipped with the developer preview, you can view the types in the files visually. You can also use ildasm to dump a text file containing the types in the metadata file. I believe that .Net reflector can also do this.

    If you DO need to enumerate types in a winmd file programmaticly, I suggest that you use the unmanaged metadata reading APIs. That's how we read metadata files for our development tools internally.

    If you're running on the developer preview build, I'll suggest you look at the RoGetMetaDataFile API - this is the API used by the Chakra javascript engine to open the metadata file for a particular type.

    0 讨论(0)
  • 2021-01-20 09:17

    To work with *.winmd files you must set in your project file inside PropertyGroup

    <TargetPlatformVersion>8.0</TargetPlatformVersion>
    
    0 讨论(0)
提交回复
热议问题