473,322 Members | 1,734 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,322 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 2779
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: 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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.