1

We are writing an application that has to run on Windows 7... and we can't install a new version of the .NET framework on those client machines. As the developer, I want to use all the fancy new C# 6.0 language features, and if I understand correctly, the language and the framework have been decoupled.

I just need clarification: If I target C# 6.0 in my application, will the code still run correctly on a Win7 client with .NET 4.0 as the highest framework version?

Scott Baker
  • 10,013
  • 17
  • 56
  • 102

1 Answers1

3

Yes, you can use a C# 6 compiler while targeting an older version of .NET. The way this usually works is that you have a newer version of Visual Studio and target it at a specific .NET version. For C# 6, this means VS2015. You will be able to use any new C# features, as long as they don't rely on .NET libraries. In particular cases, such as if you want to use async stuff, there are backward compatibility libraries available.

You could also use csc.exe (C# compiler) directly, and bypass Visual Studio.

Community
  • 1
  • 1
Tim S.
  • 55,448
  • 7
  • 96
  • 122
  • Per the documentation, the Microsoft Async NuGet package you linked to requires .NET 4.5 or greater... but still a great answer. – Scott Baker Apr 18 '16 at 17:42
  • Note that most features that are new in C# 6.0 should work on .Net 4.0 just fine. One exception would be the rather obscure case of using string interpolation with `FormattableString` (string interpolation with `string` should work). – svick Apr 18 '16 at 17:43
  • @ScottSEA Where do you see that? I see: "Supported Platforms: .NET Framework 4 (with KB2468871)". – svick Apr 18 '16 at 17:43
  • @ScottSEA I see what you are referring to, the page is a little confusing. They're not saying you should generally use the package in .NET 4.5. They're saying that if you are using .NET 4.5, the only reason to include Microsoft.Bcl.Async is if you reference a .NET 4 package that uses Microsoft.Bcl.Async. See [this q/a](http://stackoverflow.com/q/9110472/781792) for a ref on using it in .NET 4. – Tim S. Apr 18 '16 at 18:11
  • @TimS. Ah! Thanks for the clarification! – Scott Baker Apr 19 '16 at 16:37