使用 CodeDomProvider 在调试模式下编译源代码
我有一些源代码想要使用 Microsoft.CSharp.CSharpCodeProvider
类进行编译,并且我想包含特定于调试版本的内容(例如,标有 [Condtional (“DEBUG”)]
属性)。
我尝试将 CompilerParameters.CompilerOptions 属性设置为“/debug”,但是当我运行编译后的代码时,调试内容似乎并未包含在内;所以我怀疑这不是完成我想要的事情的正确方法。
我该怎么做?
I have some source code I'd like to compile using the Microsoft.CSharp.CSharpCodeProvider
class, and I want to include stuff that's specific to debug builds (e.g., methods marked with the [Condtional("DEBUG")]
attribute).
I tried setting the CompilerParameters.CompilerOptions
property to "/debug", but when I ran the compiled code the debug stuff didn't seem to be included; so I suspect that wasn't the correct way to accomplish what I want.
How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该能够将
CompilerOptions
设置为/d:DEBUG
,这将定义DEBUG预处理器符号。这就是条件编译所基于的,而不是/debug
标志 - 后者控制是否发出调试信息。You should be able to set
CompilerOptions
to/d:DEBUG
which will define the DEBUG preprocessor symbol. That's what conditional compilation is based on, rather than the/debug
flag - the latter controls whether debug information is emitted.