Skip to content

Instantly share code, notes, and snippets.

@van800
Created May 25, 2018 08:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save van800/875ce55eaf88d65b105d010d7b38a8d4 to your computer and use it in GitHub Desktop.
Save van800/875ce55eaf88d65b105d010d7b38a8d4 to your computer and use it in GitHub Desktop.
How to make Rider CsprojAssetPostprocessor the last one
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);
}
}
Copy link

ghost commented Aug 26, 2018

@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?

@van800
Copy link
Author

van800 commented Aug 31, 2018

@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