Question: The trusty old preprocessor directive in C# appear to work great when I write:

```
#if DEBUG
...
(Some code)
...
#endif

```

However, attributes enclosed in the conditional block appear to continue to get processed and I get errors indicating such. For instance, surrounding an `[AssemblyVersion(...)]` within the conditional block appears to have no affect.

I can go into the details as to why we want to conditionally ignore the [AssemblyVersion(..)], but it's irrelevant. Any ideas?

Answer: 
This works correctly for me. In my AssemblyInfo.cs file, I have the following:

```
#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
#else
[assembly: AssemblyConfiguration("Release")]
#endif

```

Looking at the compiled assembly in Reflector, I see the correct attributes.

You should make sure that your DEBUG symbol is only defined in the project **properties** and not any where else in your code as an actual #define DEBUG instruction. If you have it defined directly in code it will only be in effect for that file, not the entire project. Defining it in the project properties will cause it be in effect for the entire project.
simpler - you can tag your debug function(s) with the metadata tag [Conditional]:

```
#define DEBUG1

...

public static void PrintText1(string txt)   {
    Console.Write("This is PrintText2\n");
}

[Conditional("DEBUG1")]
public static void PrintText2(string txt)   {
    Console.Write("This is PrintText2\n");
}

[STAThread]
static void Main(string[] args)    {
    PrintText1("This is the unconditional method");
    PrintText2("This function will be called only if 'DEBUG1' is defined");
}

```

try it!

Also, what I noticed is that `#define` only exists within the context of the file it is defined, ex calling PrintText2 from another file, where debug is not defined, will not execute. This also works the other way around:

```
[Conditional("DEBUG1")]
public static void ConditionedPrint(string txt) {
    Console.Write("This is PrintText2\n");
}

public static void UnconditionedPrint(string txt)     {
    ConditionedFunc(txt);
}

```

UnconditionedFunc will print "This is PrintText2\n" iff (if and only if) #define DEBUG1 was defined in *this* file, regardless of the other files.

There is also System.Diagnostics.Debug, I'm not sure what it does though.