0

I know that with the following command I can get the runtime version

var runtimeVer = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;

In my case it returns ".NET 6.0.7"

What i need is to verify programmatically that the version is > 6.0.4.

I would prefer not doing that with a string compare. Is there any best practice or better alternative?

UPDATE: I do not just need a way to get the current version, but a safe way to make sure if it is newer than a specific version, while avoiding string comparison or regex complex expressions

Charlieface
  • 52,284
  • 6
  • 19
  • 43
cnom
  • 3,071
  • 4
  • 30
  • 60
  • 1
    `Environment.Version` maybe? – Charlieface Jul 15 '22 at 08:31
  • Does this answer your question? [Get Current .NET CLR version at runtime?](https://stackoverflow.com/questions/1826688/get-current-net-clr-version-at-runtime) – Charlieface Jul 15 '22 at 08:32
  • Thank you, but not actually. I need to compare it with a specific version and see if the current is newer. ie. something like "6.0.7" > "6.0.4" – cnom Jul 15 '22 at 10:53
  • So what's wrong with `System.Environment.Version > new Version(6, 0, 4)` – Charlieface Jul 15 '22 at 10:59
  • That works! thank you, do you want to add it as an answer so I accept it? – cnom Jul 15 '22 at 11:19
  • You should have a link above to accept the suggested duplicate – Charlieface Jul 15 '22 at 11:20
  • But, that is not duplicate, it is just related, on the getting part. I needed the way to compare it. I already made a relevant update. – cnom Jul 15 '22 at 11:22
  • Seems a bit too simple to have a whole separate question "How to compare two `Version` objects?" answer "Use `>`" – Charlieface Jul 15 '22 at 11:23
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/246463/discussion-between-cnom-and-charlieface). – cnom Jul 15 '22 at 11:24

1 Answers1

0

With the helpful comment of Charlieface I managed to do exactly what I was trying with the following code

  if (System.Environment.Version > new Version(6, 0, 4))
        {
          //do whatever needed, the runtime version supports it
        }
cnom
  • 3,071
  • 4
  • 30
  • 60