简体   繁体   English

如何从F#dll重建F#程序集签名

[英]How to reconstruct F# assembly signature from F# dll

I want to access F# signature data from a compiled F# dll. 我想从已编译的F#dll访问F#签名数据。

I understand that I can get the signature data from the source files using the FSharp.Compiler.Service library. 我知道可以使用FSharp.Compiler.Service库从源文件中获取签名数据。 I could not find a way to use that library to produce signature information from a dll without sources. 我找不到使用该库从没有源的dll中生成签名信息的方法。

I see two options, but I think it's possible there may be a simpler solution. 我看到两个选择,但我认为可能有一个更简单的解决方案。 The two options I'm aware of are: 我知道的两个选项是:

  1. Embed the F# source code in the dll and use FSharp.Compiler.Service to extract information from the embedded resource. 将F#源代码嵌入dll中,并使用FSharp.Compiler.Service从嵌入式资源中提取信息。 I could then make any associations to reflection metadata from correspondence in name. 然后,我可以将名称对应中的反射元数据建立任何关联。 Unless I did something wrong, FSharp.Compiler.Service can't interpret an .fsi signature file, so it seems that the whole source would need to be embedded for this to work. 除非我做错了什么,否则FSharp.Compiler.Service无法解释.fsi签名文件,因此似乎需要嵌入整个源才能起作用。

  2. Reconstruct the F# signature from reflection metadata. 从反射元数据重构F#签名。 This approach seems necessarily insufficient because some data is not recoverable through reflection (eg type aliases). 由于某些数据无法通过反射(例如类型别名)进行恢复,因此该方法似乎不一定足够。

My question is: 我的问题是:

Is there a better way to access F# signature data and associate it with reflection metadata than I have suggested? 是否有比我建议的更好的方法来访问F#签名数据并将其与反射元数据相关联?

Another way to look at this question that might make it a little more concrete is, "Given a compiled F# assembly, how can I determine all the type aliases (and referents thereof) that would be available to referencing projects?" 解决这个问题的另一种方法可能是,“给出一个已编译的F#程序集,我如何确定所有可用于引用项目的类型别名(及其引用)?”

This is essentially what the Library documentation part of F# Formatting does. 这实质上是F#格式库文档部分所做的。 It generates documentation from a compiled DLL (together with the XML comments), but the key part is that it loads the metadata about the F# code from the compiled DLL. 它从已编译的DLL(以及XML注释)生成文档,但是关键部分是它从已编译的DLL加载有关F#代码的元数据。

The way it works is that it uses the F# Compiler Service to build a project 它的工作方式是使用F#编译器服务来构建项目

It uses the F# Compiler Service to load the compiled F# DLL (as if you were referencing it when compiling some code). 它使用F#编译器服务来加载已编译的F#DLL(就像在编译某些代码时引用它一样)。 The F# compiler service then sees all the information about the DLL, including things like aliases (that's what the F# compiler itself sees when you reference a DLL!) 然后,F#编译器服务会看到有关DLL的所有信息,包括诸如别名之类的东西(这是F#编译器本身在引用DLL时所看到的!)

The source code for it is on GitHub - good starting point is the call to FSharpAssembly.LoadFiles here , which reads the meta-data that is later processed. 它的源代码在GitHub上-很好的起点是对这里的 FSharpAssembly.LoadFiles的调用,该文件读取稍后处理的元数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM