【发布时间】:2015-01-03 00:17:41
【问题描述】:
有没有办法通过反射获取程序集的原始源代码位置?
警告,我不是在寻找程序集的当前位置,而是在编译源代码时所在的位置。
例如
Given: myAssembly.dll
c:\program files\myapp\myAssembly.dll <- I'm NOT looking for this location. This is its current location.
d:\dev\myapp\main.cs <- this is the location I want; the location were the source code resided when it was compiled
我是从这个开始的,但到目前为止我还没有找到该去哪个兔子洞来获取此信息。
Assembly.GetExecutingAssembly().GetType("myAssembly.Main").<something>
当 .Net 中发生异常时,您通常会看到引发异常的类的名称以及原始源代码文件的完整路径。这就是我所追求的。我意识到可能需要一个 .pdb 符号文件才能获得此位置。
【问题讨论】:
-
我不了解反射,但您可以使用从 dbghelp.dll 库导出的函数读取 PDB 文件的内容 - 包括这些文件名。
标签: c#