Question How do I upgrade to C# 8?

glasswizzard

Well-known member
Joined
Nov 22, 2019
Messages
126
Programming Experience
Beginner
I figured you just download the latest VS and that's it, you've got the latest version of C#, but today I got an error when trying to set a property to readonly, saying "Feature 'readonly members' is not availble in C# 7.3. Please use language version 8.0 or greater."

So it seems I'm using version 7.3, how do I upgrade?
Thanks
 
I see, so VS uses .NET Core 2 by default and I need to upgrade to .NET Core 3.

I have VS version 16.4.5, .NET Core 3 should be installed with this version. I don't get any option to choose which version of .NET Core to use when starting a new project though. How do I change to .NET Core 3? If I started a project with .NET Core 2 can that project be updated to use .NET core 3?
 
I just created a C# Console App project in VS 16.4.5 and it defaulted to .NET Core 3.1. The Application page of the project properties has a drop-down for Target framework so you should be able to upgrade projects targeting older versions there.
 
A console app does indeed default to .NET Core 3.1.

Aren't WPF apps supposed to do that too? If not does that mean that WPF apps can't use C# 8 yet?
 
I just created a WPF App project and it defaulted to .NET Core 3.1 (3.0 was the only other option in the properties, as you'd expect) and I was able to add readonly members to a structure, so it must be using C# 8.0. If you have a project that was created using C# 7.3 then I'm not sure where that is specified and/or whether it can be changed. If you want to do so, maybe creating a new project and importing existing items would be your best bet. Seems odd so maybe I'm missing something... or you are.
 
It's definitely me that was missing something, I've been starting new WPF projects using .NET Framework, not .Net Core. Problem solved :)
 
Screenshot_81.jpg

Screenshot_82.jpg


Be warned, if you go up to the very latest C# version, there is no going back and you will be required to create a new project should you wish to not use the latest C# features. In my case, I am already using them, and so I can not downgrade this project to use a previous version. Nor can you edit any of the project files to reflect other versions. There is a strange bug which I reported to Microsoft regarding being locked into a specific version of C# once you upgrade your project, you can no longer downgrade a version. Hence the warning of not being able to select a different version. I don't recall how I got around this before to allow me to change C# versions, perhaps @Skydiver recalls what I did when I had this issue before.
 
Back
Top Bottom