Created
May 25, 2018 08:07
-
-
Save van800/875ce55eaf88d65b105d010d7b38a8d4 to your computer and use it in GitHub Desktop.
How to make Rider CsprojAssetPostprocessor the last one
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Reflection; | |
using UnityEditor; | |
using UnityEngine; | |
namespace JetBrains.Rider.Unity.Editor.AssetPostprocessors | |
{ | |
[InitializeOnLoad] | |
public static class Bootstrap | |
{ | |
static Bootstrap() | |
{ | |
if (UnityUtils.UnityVersion > new Version(2017, 1)) | |
{ | |
Assembly[] loadedAssemblies = (Assembly[]) ourSLoadedAssembliesGetter?.Invoke(null, new object[0]); | |
if (loadedAssemblies == null) | |
{ | |
Debug.LogError("Error getting 'UnityEditor.EditorAssemblies.loadedAssemblies' by reflection"); | |
return; | |
} | |
if (ShiftToLast(loadedAssemblies, a => Equals(a, typeof(CsprojAssetPostprocessor).Assembly))) | |
{ | |
CsprojAssetPostprocessor.OnGeneratedCSProjectFiles(); | |
} | |
} | |
} | |
private static bool ShiftToLast<T>(this T[] list, Predicate<T> predicate) | |
{ | |
int lastIdx = list.Length - 1; | |
int idx = Array.FindIndex(list, predicate); | |
if (lastIdx < 0 || idx < 0 || idx == lastIdx) return false; | |
T temp = list[idx]; | |
Array.Copy(list, idx + 1, list, idx, lastIdx - idx); | |
list[lastIdx] = temp; | |
return true; | |
} | |
private static readonly MethodInfo ourSLoadedAssembliesGetter = typeof(EditorWindow) | |
.Assembly.GetType("UnityEditor.EditorAssemblies") | |
?.GetProperty("loadedAssemblies", BindingFlags.Static | BindingFlags.NonPublic) | |
?.GetGetMethod(true); | |
} | |
} |
@nearautomata
For some reason I am not getting notifications about the gist comments.
It is better to rise an issue in https://github.com/JetBrains/resharper-unity/
Please mention your OS, Unity version, what value exactly ends up in LangVersion Property in csproj?
And please add logs similar to requested here
JetBrains/resharper-unity#751 (comment)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@van800 I am using this in my Unity project since Rider did not want to accept the override lang version option set to 6 and was always handling the project assuming it is targetting C# 7 with suggestions such as inlined out variables that do not work in Unity yet. Unfortunately with the Rider version JetBrains Rider 2018.2 #RD-182.4231.193 it no longer works for me. Is this a known issue yet?