How to specify c# version in visual studio?

I’m using unity 2019 with visual studio. Unfortunately visual studio is using the wrong version of c#. Is there a way I can fix this? Unity 2019 used c# 7 whereas my VS is using a later version. Mostly this doesn’t matter but it keeps putting up warnings about me not using features that don’t exist it c# 7.

If the Unity Visual Studio integration within Unity3D is set up properly, the project / solution files should be set up for correctly. Here’s more:

This may help you with intellisense and possibly other Visual Studio integration problems:

Sometimes the fix is as simple as doing Assets → Open C# Project from Unity. Other times it requires more.

Other times it requires you also nuke the userprefs and .vsconfig and other crufty low-value high-hassle files that Visual Studio tends to slowly damage over time, then try the above trick.

Barring all that, move on to other ideas:

Also, try update the package inside of Unity: Window → Package Manager → Search for Visual Studio Editor → Press the Update button

Depending on flavor and version of Visual Studio, it may also have an installation step that you perform within the actual Visual Studio. This step seems finicky at best and may require multiple openings of VS before it comes up.

Update: The VSCode extension has been deprecated and abandoned:

Update: the VSCode integration is back… maybe!?

There may be a community fork available that is receiving updates.

Also, this tidbit:

Recently (July 2023) I worked on a Windows11 system that required a Microsoft component to be installed from within Visual Studio before it would work properly with all the OTHER software installed under Unity. I have no documentation on that process as I have only seen it once and it surprised me as well.

Are you perhaps using it with a Visual Studio version newer than what Unity 2019 officially supported? Because you can get all sorts of issues doing so.

Unless you’re maintaining a legacy project facing a super challenging brick wall upgrading to Unity 2020+ it’s about time to upgrade. That project is now four LTS versions behind the status quo, and 2019 is starting to move into that state of aging software where publishing with that version will become increasingly troublesome, if not impossible especially on mobile.

thanks for the tips Kurt & Codesmile. I tried deleting the vs project but that didn’t fix it. I looked at the project file itself and found it had the LangVersion set to “latest” rather than an actual version so I could fix it by changing the version number here but then the changes are lost the next time the project is remade.

As for upgrading, the code I am working is a tool that needs to work on lots of different versions of Unity, so I decided to use an early version.

Okay, that makes sense IF AND ONLY IF you have lots of (legacy) projects that absolutely cannot be updated and absolutely require this tool.

Otherwise if you plan to publish this to the public it’s a complete and utter waste of your time to support anything below 2022.3. Honestly, for a new tool you can just raise it to 6.0 and add “for Unity 6” to the title to completely offset any (little) loss of sales to 2022.3 users because users like tools “made for (latest)”.

According to the quarterly updated metrics of which paid assets get installed into which Unity version, the trend for years now has been like this:

  • Current LTS: > 60% to 90% (grows over the LTS period)
  • Last (out of support) LTS: 35% to 8%
  • Second to last LTS: 2% to 4%
  • Even older: 0% to 1%

So I keep telling publisher that it’s COMPLETELY BONKERS to design, test, and correct a tool running on less than “last Unity LTS”. It is waste, waste, waste, and headaches only for zero benefit.

The tool I am working on is something that allows me to log bugs inside an app. I have numerous projects that I plan to use it for. Mostly they use more recent versions of Unity but I have one project for the Oculus Go that only works on an old version.

The annoying thing is it keeps suggesting I use features from newer c# and it will build in vs itself but is broken in unity. Also as I am more used to the new c# I keep accidentally using features from that.