4

If I want to use the new features of C# 7.0 in my application code, what is the lowest version of .NET that must be installed on the client machine for my app to be able to run?

Graham
  • 7,431
  • 18
  • 59
  • 84
Sean Kearon
  • 10,987
  • 13
  • 77
  • 93
  • Do you mean to *run* code compiled with C# 7 syntax, or which SDK to install to be able to *compile* code that contains C# 7 syntax? – Lasse V. Karlsen Mar 12 '17 at 10:31
  • I mean to run the code compiled with C# 7 syntax. That's what I was trying to say by asking what needs to be _installed on the client machine_. – Sean Kearon Mar 12 '17 at 10:33
  • @LasseV.Karlsen the question said `to be able to run` – zaitsman Mar 12 '17 at 10:33
  • I suspect it will be possible to target lesser versions, but some features of C#7 require runtime support via NuGet (eg. [System.ValueTuple](https://www.nuget.org/packages/System.ValueTuple/)) which will impose their own dependencies. – Richard Mar 12 '17 at 10:35
  • Yes - does that not read very well, zaitsman? – Sean Kearon Mar 12 '17 at 10:35
  • Then you should be able to get by with .NET 2.0. If you use parts that the C# compiler relies upon that require new types in the .NET framework then I am pretty sure there are nuget packages that can be installed that provides everything you need. In particular, for the only thing in new in C# 7 that require such things, the tuples, the nuget package [System.ValueTuple 4.3.0](https://www.nuget.org/packages/System.ValueTuple/) should be enough. There are bits in C# 5 and 6 as well that require similar packages. – Lasse V. Karlsen Mar 12 '17 at 10:35
  • @lasse-v-karlsen - quite likely the case, but if it can be done with Nuget packages then where are the docs to show what's needed. – Sean Kearon Mar 12 '17 at 10:39
  • If you going to use `async-await` feature, then Net 3.5 will be lowest possible version with required NuGet packages - "AsyncBridge" – Fabio Mar 12 '17 at 10:40
  • I am not sure it is documented as such in one place. Be sure that the compiler will not let you compile something for which you haven't added the requisite nuget package so you should easily be able to figure out what is needed when the compiler complains. – Lasse V. Karlsen Mar 12 '17 at 10:41
  • That's a shame - perhaps it would be a good addition to the Stack Overflow docs in the first link in the question body? – Sean Kearon Mar 12 '17 at 10:42

1 Answers1

2

Language version (and language features) is not tied to .NET version and resulting CIL should be running well on each CLR. It is mostly syntactic sugar.

Here you have a list and I do not see any language features here that would depend on CLR version.

Framework version

Mateusz
  • 2,287
  • 20
  • 28
  • 4
    Though this is true, some of the C# syntax that has been introduced in the later C# versions require support from the underlying .NET framework in terms of specific classes being present. These can either be manually implemented/copied into the project, brought in via a Nuget package, or of course be available with the use of one of the later .NET framework versions as well. Specifically, for C# 7, I believe only the tuples this time around rely on framework classes, which are easily brought in via a Nuget package. – Lasse V. Karlsen Mar 12 '17 at 10:40