views:

13

answers:

1

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?

+2  A: 

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.

Jon Skeet