1

Added small code to find .NET version at runtime in:

  1. sample program
  2. proprietary app.

            var version = Environment.Version;
            Console.WriteLine(version.ToString());
    

Both were compiled with target version .NET Framework 4.

Sample prog output is 4.0.30319.255

proprietary app output is 2.0.50727.8000

Sample prog is being compiled and run on same machine.

This proprietary app is getting compiled on one build machine and deployed on other production machine.

Why this difference of version is there.

Where should I look for this issue in proprietary app . Give me some pointers.

  • is that work for you – Pranay Rana Jul 09 '15 at 06:14
  • I'd suspect the build process on your build machine ignores the target framework 4 specified in the project file and uses 3.5 instead. This may be due to the MSBuild version and its target framework. – Filburt Jul 09 '15 at 06:23

2 Answers2

1

First Check documentation:

Environment.Version Property

Gets a Version object that describes the major, minor, build, and revision numbers of the common language runtime.

Caution

For the .NET Framework 4.5 later, we do not recommend using the Version property to detect the version of the runtime; instead, you can determine the version of the common language runtime by querying the registry. For more information, see How to: Determine Which .NET Framework Versions Are Installed.

Refer below link for more clarification about your question:
How do I detect at runtime that .NET version 4.5 is currently running your code?

With 2.0 vs. 3.0 or 3.5 Environment.Version was of no help since it always returned 2.0 as all those framework versions were using the CLR 2.0.

Read it too: NET Versioning and Multi-Targeting - .NET 4.5 is an in-place upgrade to .NET 4.0

Note that this in-place replacement is very different from the side by side installs of .NET 2.0 and 3.0/3.5 which all ran on the 2.0 version of the CLR. The two 3.x versions were basically library enhancements on top of the core .NET 2.0 runtime. Both versions ran under the .NET 2.0 runtime which wasn’t changed (other than for security patches and bug fixes) for the whole 3.x cycle. The 4.5 update instead completely replaces the .NET 4.0 runtime and leaves the actual version number set at v4.0.30319

References:
Why does System.Environment.Version report framework 2?

Community
  • 1
  • 1
Niranjan Singh
  • 18,017
  • 2
  • 42
  • 75
0

Environment.Version gives you the version of CLR use, not the .Net framework itself

See How do I detect at runtime that .NET version 4.5 is currently running your code?

Community
  • 1
  • 1
Eric
  • 5,675
  • 16
  • 24
  • Eric I need to detect version for code compiled for .NET version 4 and .NET version 2 – Vikram Singh Jul 09 '15 at 06:45
  • @VikramSingh Check this http://stackoverflow.com/questions/3436526/detect-target-framework-version-at-compile-time – Eric Jul 09 '15 at 06:59