views:

73

answers:

3

Hi all

I am writing a program which is targeted to run on .net framework 2.0.

I have chosen 2.0 in my VS project.

It runs fine on my machine (mine has 2.0 SP2), so there is no compile error. but when I tried to run it on another machine (only with 2.0, no sp), it cannot run. I am aware that I used some method which is supported by 2.0 but only with 2.0 SP2.

.net framework 2.0 SP2 seems not being listed in VS IDE, that's why VS cannot give me any warning when I compiled it on my machine.

How can I easily check the compatibility of my codes with .net framework 2.0 SP2? or I just have to look at msdn to check every method I have used???

thanks

A: 

If you know for sure which specific libraries (dll) distinguish 2.0 SP2 from just 2.0, you can attempt to programmatically locate and load them. If it fails, then the SP2 is not present.

In case there is no "new" dlls, you could use reflection to check if a class has a specific method. If it does, you've got SP2.

It is a solution for run-time, so you can display a friendly message to the user.

Developer Art
What if I don't know any? in the above e.g., I used some method in the library of 2.0, but the compiler did not tell me it is for 2.0 SP2. I just want to know is there any easy way to know which method or class is from 2.0 SP2 or more precise .net framework version?
Jack
@Jack: Look at the method description on MSDN pages. It always says which framework version support it, including SP data.
Developer Art
+4  A: 

You can run FxCop, which will warn you whenever you call a method introduced by a service pack.

SLaks
Thanks. you mean I use FxCop to analyse the codes, it will tell me if I call a method from 2.0 SP2?
Jack
More info: http://davesbox.com/archive/2008/08/25/new-for-visual-studio-2008-sp1-and-fxcop-1-36-multi-targeting-rule.aspx
Ray
@Jack: Yes, it will.
SLaks
Thanks all. FxCop fills what I need. Very helpful. Thanks
Jack
A: 

You can identify where in your code is the error when no sp is present.

Then, you just create a dummy snippet that use that structure, and catch the exception.

If no exception is catched, you are ok. If an exception is thrown, you are probably missing sp2.

Daniel Dolz