public override void SetLanguageLevel(IPsiModule psiModule, CSharpLanguageLevel languageLevel)
 {
     throw new InvalidOperationException("Language level cannot be set for a T4 module.");
 }
		public override void SetLanguageLevel(IPsiModule psiModule, CSharpLanguageLevel languageLevel) {
			throw new InvalidOperationException("Language level cannot be set for a T4 module.");
		}
Exemple #3
0
        private void InitLanguageLevelSettings(IProject project, SettingsStorageMountPoint mountPoint)
        {
            if (!project.IsProjectCompiledByUnity())
            {
                return; // https://github.com/JetBrains/resharper-unity/issues/150
            }
            // Make sure ReSharper doesn't suggest code changes that won't compile in Unity
            // due to mismatched C# language levels (e.g. C#6 "elvis" operator)
            //
            // * Unity prior to 5.5 uses an old mono compiler that only supports C# 4
            // * Unity 5.5 and later adds C# 6 support as an option. This is enabled by setting
            //   the API compatibility level to NET_4_6
            // * The CSharp60Support plugin replaces the compiler with either C# 6 or C# 7.0
            //   It can be recognised by a folder called `CSharp60Support` or `CSharp70Support`
            //   in the root of the project
            //   (https://bitbucket.org/alexzzzz/unity-c-5.0-and-6.0-integration)
            //
            // Scenarios:
            // * No VSTU installed (including Unity 5.5)
            //   .csproj has NO `LangVersion`. `TargetFrameworkVersion` will be `v3.5`
            // * Early versions of VSTU
            //   .csproj has NO `LangVersion`. `TargetFrameworkVersion` will be `v3.5`
            // * Later versions of VSTU
            //   `LangVersion` is correctly set to "4". `TargetFrameworkVersion` will be `v3.5`
            // * VSTU for 5.5
            //   `LangVersion` is set to "default". `TargetFrameworkVersion` will be `v3.5` or `v4.6`
            //   Note that "default" for VS"15" or Rider will be C# 7.0!
            // * Unity3dRider is installed
            //   Uses Unity's own generation and adds correct `LangVersion`
            //   `TargetFrameworkVersion` will be `v3.5` or `v4.6`
            // * CSharp60Support is installed
            //   .csproj has NO `LangVersion`
            //   `TargetFrameworkVersion` is NOT accurate (support for C# 6 is not dependent on/trigger by .net 4.6)
            //   Look for `CSharp60Support` or `CSharp70Support` folders
            //
            // Actions:
            // If `LangVersion` is missing or "default"
            // then override based on `TargetFrameworkVersion` or presence of `CSharp60Support`/`CSharp70Support`
            // else do nothing
            //
            // Notes:
            // * Unity and VSTU have two separate .csproj routines. VSTU adds extra references,
            //   the VSTU project flavour GUID and imports UnityVs.targets, which disables the
            //   `GenerateTargetFrameworkMonikerAttribute` target
            // * CSharp60Support post-processes the .csproj file directly if VSTU is not installed.
            //   If it is installed, it registers a delegate with `ProjectFilesGenerator.ProjectFileGeneration`
            //   and removes it before it's written to disk
            // * `LangVersion` can be conditionally specified, which makes checking for "default" awkward
            // * If Unity3dRider + CSharp60Support are both installed, last write wins
            //   Order of post-processing is non-deterministic, so Rider's LangVersion might be removed
            // * Unity3dRider can set `TargetFrameworkVersion` to `v4.5` on non-Windows machines to fix
            //   an issue resolving System.Linq

            var languageLevel = CSharpLanguageLevel.Default;

            if (IsLangVersionMissing(project) || IsLangVersionDefault(project))
            {
                const CSharpLanguageLevel csharp70 = CSharpLanguageLevel.Experimental;

                // Support for https://bitbucket.org/alexzzzz/unity-c-5.0-and-6.0-integration
                // See also https://github.com/JetBrains/resharper-unity/issues/50#issuecomment-257611218
                if (project.Location.CombineWithShortName("CSharp70Support").ExistsDirectory)
                {
                    languageLevel = csharp70;
                }
                else if (project.Location.CombineWithShortName("CSharp60Support").ExistsDirectory)
                {
                    languageLevel = CSharpLanguageLevel.CSharp60;
                }
                else
                {
                    languageLevel = IsTargetFrameworkAtLeast46(project)
                        ? CSharpLanguageLevel.CSharp60
                        : CSharpLanguageLevel.CSharp40;
                }
            }
            SetValue(mountPoint, (CSharpLanguageProjectSettings s) => s.LanguageLevel, languageLevel);
        }
 public override bool CanSetCompilerLanguageLevel(IPsiModule psiModule, CSharpLanguageLevel languageLevel)
 => false;