The .NET Compact Framework has had several releases: V1 + 3 service packs, V2 + 2 service packs, V3.5 (to date just betas).  Which of these are installed on your device?  Can you have multiple versions installed simultaneously?  Which version will run your NetCF app if multiple versions are installed?  This post addresses all these questions.

Can you have multiple versions installed simultaneously?

NetCF supports side-by-side installations for distinct versions only.  For example, V1 and V2 may be installed on your device at the same time, but V2 and V2 SP1 may not be installed at the same time.  After V3.5 is released, if a V3.6 were to come out it could be side-by-side installed with V3.5 since it is a distinct version.

If you have a version installed in ROM and a service pack version with the same major and minor numbers installed in RAM, only the version in RAM is actually installed and will run your application.

Discovering which version(s) of NetCF is installed on your device

To see what is installed on your device right now, you can click Start -> Settings -> System -> Remove Programs and see what's listed.

To find which version(s) are installed programmatically (say for a setup program you're writing), you can check the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETCompactFramework.  There are DWORD values under it named "X.Y.BBBB.mm" for each installed version of NetCF.  A value of 0 means it is installed in RAM while a value of 1 means it is installed in ROM.  Beware that if a version is in ROM (i.e. V1) and a newer build of the same version is installed in RAM (i.e. V1 SP3) then both of these will be listed as values in this registry key, although only the SP3 version will actually be present on the system.

[Added 11/29/2007] Check out Neil Cowburn's blog post that contains a table of version numbers and releases for NetCF.

Which NetCF version will run your app?

Review the flow chart or read the discussion below.

A device.config file in your \windows directory may force all applications to run against a particular version of NetCF on your device, although an app-specific .config file takes precedence.  In the absence of a device.config file (which is not present by default), the following rules apply.

If only one version of NetCF is installed on your device, it will run your app if it is at least as recent as the NetCF version that the application was built against.  So a V2 app will run on NetCF V2 and V3.5, but not on NetCF V1. 

Service packs are excluded from this check, so if an application is written against NetCF 2.0 SP2, NetCF 2.0 RTM and SP1 will also run the app.  If that app takes dependencies on SP2 bug fixes, the app may break when run on V2 RTM and should therefore check at startup time to see what version of NetCF is running it and warn the user if the appropriate service pack is not installed.  The System.Environment.Version property will allow you to check the NetCF version and service pack your app is running on.

If you have multiple versions of NetCF installed, a NetCF app will run against the version of NetCF it was compiled against if it is installed on the device.  If that version of NetCF is not installed, then the newest version of NetCF that is installed will be used.  For example, a V1 app run on a device with only V2 and V3.5 installed will run on V3.5.

You can alter the default behavior with a .config file to force your app to load with a specific version of NetCF.  For example, on a device with V2 and V3.5 installed, you can force the V1 app to run against V2 (rather than the newest V3.5) by using a .config file.  For details on this process, see the MSDN documentation How to: Configure Runtime Version.

Should you have multiple versions installed?

That depends on the applications you run and their requirements.  In theory, V2 SP2 should be able to run V1 apps because it has a "compatibility mode" that preserves old V1 behavior where needed by older apps.  V3.5 will offer the same backward compatibility feature.  But this "version coercion" feature is not perfect, and you may find that an app that runs on V1 won't run on V2.  In this case, installing V1 side-by-side with V2 is a good idea if you have memory on your device for it.