Determining the NetCF version while debugging

Have you ever wondered, while debugging, what the exact version of the .NET Compact Framework was being used by the debuggee?  If so, Visual Studio's Immediate Window can help.

Several months ago, I discussed how to cause a NetCF v1 application to run against the v2 beta.  In that post I suggested displaying the runtime version in a Label or TextBox at runtime.  In the Visual Studio debugger you can do the same thing, without changing your code, using the Immediate Window.  I use this technique to verify which NetCF version my application is using (v1, v1 SP3, etc) when I start debugging on a new device. 

The example below uses Visual Studio.NET 2003 and the NetCF WebCrawler sample.

While you are stopped in the Visual Studio debugger (ex: via a breakpoint or Run to Cursor), switch to the Immediate Window and type:

System.Environment.Version.ToString()

On my device, the result is "1.0.4292.0", which is NetCF v1 SP3.

If you would like to view the individual fields of the Version object, you can leave off the ".ToString()" from the previous command.

System.Environment.Version

This will result in something that looks like the following:
{System.Version}    System.Object: {System.Version}    _Build: 4292    _Major: 1    _Minor: 0    _Revision: 0    Build: 4292    Major: 1    Minor: 0    Revision: 0

Enjoy!
-- DK

Disclaimer(s):
This posting is provided "AS IS" with no warranties, and confers no rights.