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 hidden or 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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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)