473,657 Members | 2,559 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Conditional compiling

I need to be able to support multiple versions of c#. Does the compiler
define any #defines so you can tell if you are compiling for.NET 1.1 or 2.0?
Mar 28 '06 #1
10 1849
I'm sure that you have a good reason, but I'm curious... why?

Mar 28 '06 #2
I wouldn't think so. Its a different compiler when targeting 1.1 or
2.0, which is why VS 2005 only works with 2.0 and 2003 1.1.

FWIW, you should be able to compile to 1.1, and still have your
assembly loaded by .net 2.0 if you need to. Just take your 1.1
assembly and reference in your 2.0 project... should work just fine.

Mar 28 '06 #3
I'm not 100% sure, but I would assume that if you need to target both
systems with the 2.0 Framework and other systems that have only the 1.1
Framework, you would simply stick to VS2003.

Although I can't make a solid claim to this, I believe that code
compiled for 1.1 will run on systems that have only the 2.0 Framework
installed. We have tried code that we have written here on a machine
that has only 2.0, not 1.1, and it runs fine, and we are still on
VS2003.

Of course, our code does not exercise all of the capabilities of the
Framework, so there may be version incompatibiliti es, but in this
newsgroup I've heard of only one.

Mar 28 '06 #4
Andy <aj*****@alum.r it.edu> wrote:
I wouldn't think so. Its a different compiler when targeting 1.1 or
2.0, which is why VS 2005 only works with 2.0 and 2003 1.1.
There's no reason why you shouldn't run the two compilers on the same
code and get different results though...
FWIW, you should be able to compile to 1.1, and still have your
assembly loaded by .net 2.0 if you need to. Just take your 1.1
assembly and reference in your 2.0 project... should work just fine.


That's not terribly easy if you want to provide an API which uses
generics in 2.0 but not in 1.1...

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 29 '06 #5
<i>There's no reason why you shouldn't run the two compilers on the
same
code and get different results though... </i>

You may get different results using a different complier, but if you
compiled with the 1.1 compiler, the bytecode produced should run just
fine on 2.0 as well.

<i>That's not terribly easy if you want to provide an API which uses
generics in 2.0 but not in 1.1... </i>

The poster wanted to run the same code though two different compilers,
he didn't say anything about using the new features in 2.0 (which I
assume he wouldn't want to, because I got the impression he wanted a
single code base, not branched versions).

Mar 29 '06 #6
Andy <aj*****@alum.r it.edu> wrote:
<i>There's no reason why you shouldn't run the two compilers on the
same
code and get different results though... </i>

You may get different results using a different complier, but if you
compiled with the 1.1 compiler, the bytecode produced should run just
fine on 2.0 as well.
Yes, but you may find that you're limited in terms of options - you
can't provide (or use) generics, for instance.
<i>That's not terribly easy if you want to provide an API which uses
generics in 2.0 but not in 1.1... </i>

The poster wanted to run the same code though two different compilers,
he didn't say anything about using the new features in 2.0 (which I
assume he wouldn't want to, because I got the impression he wanted a
single code base, not branched versions).


You can have a single source code base which produces a richer API for
..NET 2.0, however.

Put it this way - I've been considering a few situations where I've
wanted exactly this functionality - to produce one version of a library
for use by .NET 1.1 clients, and a different version for use by .NET
2.0 clients. Of course, .NET 2.0 clients *could* use the 1.1 library,
but they'd get extra features if they used the 2.0 version.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 29 '06 #7
>Yes, but you may find that you're limited in terms of options - you
can't provide (or use) generics, for instance.
True, but thats what you have to do if you really want to target both
frameworks with a single codebase.
You can have a single source code base which produces a richer API for
.NET 2.0, however.
Currently I don't see how; run .Net 2.0 specific code through the 1.1
compiler, and you'll get errors.
Put it this way - I've been considering a few situations where I've
wanted exactly this functionality - to produce one version of a library
for use by .NET 1.1 clients, and a different version for use by .NET
2.0 clients. Of course, .NET 2.0 clients *could* use the 1.1 library,
but they'd get extra features if they used the 2.0 version.


I don't think its there however, and I doubt it will be. I believe MS'
position on this is that if you want to target 1.1 and up, you target
1.1.

I'd also have to think that managing a codebase using #define
directives would be pretty expensive. You'd have to have two sets of
tests, since you're compiling different code based on a flag. It
hardly seems like it'd be worth the trouble.

Mar 29 '06 #8
Andy <aj*****@alum.r it.edu> wrote:
Yes, but you may find that you're limited in terms of options - you
can't provide (or use) generics, for instance.


True, but thats what you have to do if you really want to target both
frameworks with a single codebase.


Not really. Often there may be fairly small differences between the
code supporting the different versions - differences which are small in
terms of lines of code but very important from the point of the view of
the user of the class.
You can have a single source code base which produces a richer API for
.NET 2.0, however.


Currently I don't see how; run .Net 2.0 specific code through the 1.1
compiler, and you'll get errors.


Not if you've conditionalised the code though - and that's what the OP
wants, from the way I read it.
Put it this way - I've been considering a few situations where I've
wanted exactly this functionality - to produce one version of a library
for use by .NET 1.1 clients, and a different version for use by .NET
2.0 clients. Of course, .NET 2.0 clients *could* use the 1.1 library,
but they'd get extra features if they used the 2.0 version.


I don't think its there however, and I doubt it will be. I believe MS'
position on this is that if you want to target 1.1 and up, you target
1.1.

I'd also have to think that managing a codebase using #define
directives would be pretty expensive. You'd have to have two sets of
tests, since you're compiling different code based on a flag. It
hardly seems like it'd be worth the trouble.


It depends on the benefits gained by using the 2.0 features. In some
cases there could be *massive* benefits. I was considering writing a
mock object framework in C# (a successor to EasyMock.NET) which would
have been significantly easier to use in 2.0 with generics, but which
I'd still have wanted a 1.1 version of.

It would certainly be easier to share 90% of the code than to maintain
two separate codebases which contained the same logic but slightly
different APIs. *Then* I really would need to double the test effort,
instead of having one set of common tests, one which only ran on 2.0
and one which only ran on 1.1.

Now, it could well be that you're right about MS's point of view - but
that doesn't mean it's not feature which could be very, very useful to
some people. MS has been known to miss the boat on things before - look
at how many people want to be able to target 1.1 with VS 2005 (and the
subsequent MSBEE effort.)

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 29 '06 #9
Just to follow up here. In general, Jon has pretty much stated my case for
me.

My project requirements include delivering source code, and the target
audience is varied. Even without using any new 2.0 features, just getting a
clean compile requires changes.

So I either need to make two source trees with 99%+ of the code being
identical (and remember to make all future changes twice), or I need to have
1 tree with a few #if statements: ~50 in the ~25,000 lines of code, most of
which wrap a single line.

It's not like I'm talking about a brand new concept. MS's C compiler has
supported this for forever (see _MSC_VER in
http://msdn2.microsoft.com/en-us/lib...y(VS.80).aspx). Heck, they
even have a __CLR_VER. Of course they also support #if __CLR_VER > xxx.

At this time, my solution is to have two sets of sln+csproj files (which I
have to have anyway), and to have USING_NET11 defined in the old project
file. I believe it would have been cleaner to use a well-known,
compiler-defined variables for this, but apparently that was not meant to
be. As near as I've been able to discover, there aren't *any* compiler
defined defines.

Thanks for the posts.
Mar 29 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
1868
by: Guy Hocking | last post by:
Hi there, I am having a few problems compiling a list box that is conditional on what is selected in another list box. What i need is a List box (lstArea) that displays one thing when the List Box (lstRegion) is selected East or West. Basically the areas will change when East or West is selected in lstRegion. The data comes from an SQL Server view, and my current non-working code is as follows, my syntax in the SQL statement is...
11
2459
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 difficult to understand. I've described it as GOTO's on steroids, and that's what it is!. One argument against abolishing it it that it is useful for conditional compilation when porting code, etc. Well, it seems to me C++ supports that...
13
6079
by: Andrew | last post by:
I use conditional compiler constants, set through the VBA IDE in Tools, <projectname> Properties, that I refer to throughout my code to control which code is used during development, and which during production. Usually, this only wraps code used to control quitting the whole app versus just shutting a form, but it can also control many other things. However, as part of the build before delivering an update, I have to remember to...
12
2485
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 main()
10
28625
by: John Smith | last post by:
After reading C# documentation the Conditional attribute seemed the way to go, but after inspecting the IL it seems those methods are still there and I imagine the CLR removes them. Using #if DEBUG means the code does not even reach the IL when compiling in release mode. Is there any benefit to using the Conditional Attribute? Am I right in thinking there will small performance overhead using over #if DEBUG.
1
1731
by: Magne Ryholt | last post by:
Using VS.net 2003 (C#) Code: : #if DEBUG something #else something else #endif
2
3201
by: GlennDoten | last post by:
Upgraded to .NET 2.0 and VS.NET'05 and while compiling code that was fine under 1.1/2003 I'm getting a fatal compiler error: Conditional member 'GetTraceMode(out System.Web.TraceMode)' cannot have an out parameter and here's the method: public static void GetTraceMode(out TraceMode mode)
1
2295
by: Marek | last post by:
I use VS2005 with framework 2.0 and I just found a behavior I consider odd. Here is the code that illustrates th eproblem: public static void MethodA() { MethodB() } #if DEBUG
3
3272
by: naunetr | last post by:
hello all, i wrote the small program below to practice conditional compiling. if i define MYSYMBOL then everthing works fine, but when i comment MYSYMBOL gcc gives the following message: cnd_compile01.c:4:2: error: #error "Error" cnd_compile01.c:1: warning: ISO C forbids an empty source file i cant understand the warning and how to eliminate it? i tried placing some dummy comment but still the same warning.
0
8392
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8305
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8825
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7324
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4151
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4302
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.