VS2005 Conditional compilation.

B

Bob

Hi,
In VS2003 conditional compilation constants and their state could be defined
at project level.
I was using this to control what features where offered by various builds.
i.e. Feature1=true,Feature2=false, ...

VS2005 seems to either allow the existance of the constant or not.
ie. You must omit a constant not declare it to be false

This means that the list no longer declares the state of all the options.
So...
I think that perhaps I am not using the right tool for the job.
What is the 'correct' way to control conditional compilation at project
level?
Thanks
Bob
 
G

Guest

Bob,
I am not sure that your post is specific enough to get an answer that will
be valuable to you.

Usually, conditional compilation directives (for a very simple example,
#If(DEBUG) )
are used to "block out" sections of code that will either get compiled into
the assembly or ignored (or in the case of specific constants, "included" in
the compilation).
Does this help?
Peter
 
M

Mattias Sjögren

In VS2003 conditional compilation constants and their state could be defined
at project level.
I was using this to control what features where offered by various builds.
i.e. Feature1=true,Feature2=false, ...

Are you sure you didn't use VB or some other language (not C#) in this
project? VB allows you to specify values for the conditional
compilation symbols, whereas they can only be defined or undefined in
C#.


Mattias
 
B

Bob

Hi Peter,
Thanks for your reply.
To rephrase:
What I was doing under VS2003 was declare a set of Custom constants in the
'Project' - 'Configuration Properties' - 'Build' page.
eg. I have one class that is shared between two projects. One project is a
service, the other is an app. By having a "Service = False" entry in the
app project and a "Service = True" entry in the Service project I could
block out the appropriate bits in each project automatically.

Now I understand that I can do the same thing in VS2005.
My 'complaint' is that you no longer can turn the constant off. ie
"Service= False" is not allowed. You must omit it from the list.
Once you have 5 or 6 constants it becomes a nightmare trying to remember
which ones to declare for which functionality. ( The above example is static
so not really a problem but I use the same technique inside a project to
produce the various flavours.
This led me to think that maybe there is another 'proper' way to control
compilation that I am missing.
regards
Bob
 
J

Jon Skeet [C# MVP]

Bob said:
Thanks for your reply.
To rephrase:
What I was doing under VS2003 was declare a set of Custom constants in the
'Project' - 'Configuration Properties' - 'Build' page.
eg. I have one class that is shared between two projects. One project is a
service, the other is an app. By having a "Service = False" entry in the
app project and a "Service = True" entry in the Service project I could
block out the appropriate bits in each project automatically.

I don't think it was actually doing what you think it was doing.

Here's a sample test app I tried in VS.NET 2003.

using System;

class Test
{
public static void Main(String [] args)
{
Console.WriteLine ("Foo");
#if Bar
Console.WriteLine ("Bar");
#endif
Console.ReadLine();
}
}

Here are the results:

Definition Bar written?
Bar Yes
(nothing) No
Bar = False Yes
Bar = True Yes
Bar=False No
Bar=True No

In other words, it's based on white-space, not the value specified.

I suggest that if you have three symbols (Foo, Bar, Baz) and want to
easily see which is turned on and off, you could use:

Foo, NoBar, Baz

etc. It's easy to see which ones are excluded, and you can easily make
sure you've got them all too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top