获取程序集的原始源代码位置

编程入门 行业动态 更新时间:2024-10-25 05:16:00
本文介绍了获取程序集的原始源代码位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否可以通过反射获取程序集的原始源代码位置的位置?

Is there a way to obtain the location of an assembly's original source code location through reflection?

警告,我不是在寻找程序集的当前位置,而是该位置是编译时源代码所在的位置.

Warning, I'm not looking for the current location of the assembly, rather the location were the source code resided when it was compiled.

例如

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

我从这里开始,但是到目前为止,我还没有找到哪个兔子洞可以得到该信息.

I started with this, but I haven't been able find which rabbit hole to go down to get this info so far.

Assembly.GetExecutingAssembly().GetType("myAssembly.Main").<something>

.Net中发生异常时,您通常会看到引发异常的类的名称以及原始源代码文件的完整路径.这就是我所追求的.我意识到,可能需要一个.pdb符号文件才能获得此位置.

When exceptions occur in .Net you'll often see the name of the class that threw the exception along with the full path to the original source code file. This is what I'm after. I realize that a .pdb symbol file may be required in order to obtain this location.

推荐答案

该信息存储在.PDB文件中.它有两种基本风格,一种是从Debug版本获得的完整版本,另一种是 stripped ,您默认从Release版本获得的版本.剥离的.PDB删除了文件和行号信息.专门删除大多数公司认为专有的细节.

That information is stored in the .PDB file. There are two basic flavors of it, the full one that you get from a Debug build and the stripped one that you get by default from the Release build. A stripped .PDB has the file and line number info removed. Pretty specifically to remove details that most companies consider proprietary.

项目+属性,构建"选项卡,高级"按钮,调试信息"对此进行设置."Full"是常规的Debug构建设置,"pdb-only"是生成剥离版本的默认Release构建设置.

Project + Properties, Build tab, Advanced button, Debug Info sets this. "Full" is the normal Debug build setting, "pdb-only" is the default Release build setting that produces the stripped version.

DbgHelp api (原生样式). DIA SDK 为此提供了更友好的COM包装器以及从中选择的通常选择C#.CLR也使用它,这就是您如何在异常的堆栈跟踪中查看文件和行的方式.

Reading the .PDB file is supported by the DbgHelp api, the native flavor. The DIA SDK provides a friendlier COM wrapper for it and the usual choice from C#. The CLR uses it too, that's how you can see the file+line in an exception's stack trace.

更多推荐

获取程序集的原始源代码位置

本文发布于:2023-11-13 12:07:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584318.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:源代码   原始   位置   程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!