using preprocessor directive for cross framework compatibility

P

Praveen

Hello all,

I have some common classes that I routinely use with all the dotnet projects
that I work with. I have these classes in a separate file so that it becomes
easy for me to include them into projects.

Some of these projects are done in visual studio 2003 and some are in visual
studio 2005. lately I have started using some of the classes (FTPWebrequest)
which are specific to the dotnet framework 2.0 (VS 2005). Now this file
cannot be included into the vs2003 projects as they would give compile
errors.

I did not want to to maintain two different files for these 2 environments.

I know that we can use preprocessor directives (#if ) for this but I did not
know how to identify the IDE version (VS 2003 or VS 2005) to use in the If
directive.

Can you help me with this.

thanks in advance,
Praveen
 
M

Michael Nemtsev

Hello Praveen,

Try to use Environment.Version method

P> Hello all,
P>
P> I have some common classes that I routinely use with all the dotnet
P> projects that I work with. I have these classes in a separate file so
P> that it becomes easy for me to include them into projects.
P>
P> Some of these projects are done in visual studio 2003 and some are in
P> visual studio 2005. lately I have started using some of the classes
P> (FTPWebrequest) which are specific to the dotnet framework 2.0 (VS
P> 2005). Now this file cannot be included into the vs2003 projects as
P> they would give compile errors.
P>
P> I did not want to to maintain two different files for these 2
P> environments.
P>
P> I know that we can use preprocessor directives (#if ) for this but I
P> did not know how to identify the IDE version (VS 2003 or VS 2005) to
P> use in the If directive.
P>
P> Can you help me with this.
P>
P> thanks in advance,
P> Praveen
---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
M

Mattias Sjögren

I know that we can use preprocessor directives (#if ) for this but I did not
know how to identify the IDE version (VS 2003 or VS 2005) to use in the If
directive.

There's no built in symbol defined to tell you the VS or framework
version, so you have to define one yourself in your project.


Mattias
 
W

Walter Wang [MSFT]

As Mattias poinsted out, there's no built-in Conditional Compilation
Constants defined to distinguish which CLR version is used. I'm afraid
you'll have to define your own constant in Project Properties/Build
settings.

I understand that it would be better if these can be offered by the
compiler automatically; please feel free to submit your feedback at
http://connect.microsoft.com/Main/content/content.aspx?ContentID=2220.
Thanks for your understanding.

Sincerely,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 

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