473,231 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

VS2005 Conditional compilation.

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
4 2776
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
>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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Steven T. Hatton | last post by:
I've made no secret of the fact that I really dislike the C preprocessor in C++. No aspect of the language has caused me more trouble. No aspect of the language has cause more code I've read to be...
2
by: Steve Jorgensen | last post by:
To begin with an example... Let's say you were wanting to write code usign early binding to the MSXML library, but then be able to switch between early and late binding at will. Conditional...
1
by: chris han | last post by:
Hi, all, I'm trying to use Conditional Compilation Statements in my code. using System; #define DEBUG public class MyClass { public static void Main() {
12
by: wanghz | last post by:
Hi, Could I ask some questions about the conditional compilaion? Suppose I have three simple files: a.c, b.c and c.h /* --------a.c--------- */ #include <stdio.h> #include "c.h" int...
2
by: FireStarter | last post by:
Guys, in the code that follows, why does the method F() still compile, even if DBG is undefined? Inside method G(), the code inside <#if DBG> does not compile (notice that I can write whatever I...
5
by: GaryDean | last post by:
(my original post was inaccurate but this post accurately describes what I think is a very bad vs2005 bug) short description... Deleting a dataset and recreating it from the dataadapter causes...
2
by: Carlo \(MCP only\) | last post by:
Hi to all I'm askyng you a suggestion about the best way to share the same source code between VS2003 and VS2005. The project I'm developing is a controls and components library, and the...
10
by: Dave | last post by:
I'm a C++ programmer of many years, trying to get my feet wet in C#. I have a question about conditional compilation. In C++, I would sometimes define a constant in an include file, and then...
6
by: maxwell | last post by:
I'm trying to use the gpp utility (Gnu points to http://en.nothingisreal.com/wiki/GPP) to do conditional compilation in Python, and I'm running into a problem: the same '#' character introduces...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.