- Home /
Unity 2018.3 + Visual Studio 2015 -> Invalid "latest" for /langversion
Hi everyone!
I am trying to upgrade our version of Unity for our project and the last error I get is about the language version of the csproj.
I know I can override by hand the version to something that visual studio does understand but is there a way to avoid all our company to do that several time per day?
Did I miss a configuration somewhere?
For the record, here is the error:
Error CS1617: Invalid option 'latest' for /langversion; must be ISO-1, ISO-2, Default or an integer in range 1 to 6.
Thanks for the help!
Florian.
P.S. I have looked at :
https://answers.unity.com/questions/1393715/error-invalid-option-6-for-langversion-must-be-iso.html
https://forum.unity.com/threads/langversion-latest-langversion-is-not-recognized-by-visual-studio.579697/
But I don't understand how they got around the error...
Answer by Tortuap · May 04, 2019 at 10:05 AM
I found a workaround, but credits goes to https://stackoverflow.com/questions/45578298/how-to-enable-c-sharp-7-features-on-unity3d-projects )
Copy & paste this into a file as Assets/Editor/FixProjectVersion.cs :
#if ENABLE_VSTU
using SyntaxTree.VisualStudio.Unity.Bridge;
using UnityEditor;
// Adapted from https://stackoverflow.com/questions/45578298/how-to-enable-c-sharp-7-features-on-unity3d-projects
[InitializeOnLoad]
public class ProjectFilesGeneration
{
static ProjectFilesGeneration ()
{
ProjectFilesGenerator.ProjectFileGeneration += ( string name, string content ) =>
{
return content.Replace
( "<LangVersion>latest</LangVersion>",
"<LangVersion>6</LangVersion>" );
};
}
}
#endif