By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,620 Members | 1,512 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,620 IT Pros & Developers. It's quick & easy.

VS2005 Conditional compilation.

P: n/a
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
Apr 22 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Bob" wrote:
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

Apr 23 '06 #2

P: n/a
>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

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Apr 23 '06 #3

P: n/a
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
"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:0A**********************************@microsof t.com...
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

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Bob" wrote:
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

Apr 23 '06 #4

P: n/a
Bob <bo*@nowhere.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 24 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.