Skip to content

Commit

Permalink
Fix project regeneration for Rider and VSCode
Browse files Browse the repository at this point in the history
  • Loading branch information
mayuki committed May 10, 2021
1 parent 5c25463 commit 916d409
Showing 1 changed file with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Unity.CodeEditor;
using UnityEngine;

namespace CsprojModifier.Editor.Features
Expand All @@ -20,21 +21,29 @@ public void OnGUI()

if (GUILayout.Button("Regenerate project files"))
{
// SyncVS.Synchronizer.Sync(); (SyncVS is an internal class, so call it with Reflection)
if (CodeEditor.CurrentEditor.GetType().Name == "DefaultExternalCodeEditor")
{
// SyncVS.Synchronizer.Sync(); (SyncVS is an internal class, so call it with Reflection)

var syncVsType = Type.GetType("UnityEditor.SyncVS, UnityEditor");
ThrowIfNull(syncVsType, "Type 'UnityEditor.SyncVS' is not found on the editor.");
var syncVsType = Type.GetType("UnityEditor.SyncVS, UnityEditor");
ThrowIfNull(syncVsType, "Type 'UnityEditor.SyncVS' is not found on the editor.");

var slnSynchronizerType = Type.GetType("UnityEditor.VisualStudioIntegration.SolutionSynchronizer, UnityEditor");
ThrowIfNull(slnSynchronizerType, "Type 'UnityEditor.VisualStudioIntegration.SolutionSynchronizer' is not found on the editor.");
var slnSynchronizerType = Type.GetType("UnityEditor.VisualStudioIntegration.SolutionSynchronizer, UnityEditor");
ThrowIfNull(slnSynchronizerType, "Type 'UnityEditor.VisualStudioIntegration.SolutionSynchronizer' is not found on the editor.");

var solutionSynchronizerField = syncVsType.GetField("Synchronizer", BindingFlags.Static | BindingFlags.NonPublic);
ThrowIfNull(solutionSynchronizerField, "Field 'Synchronizer' is not found in 'SolutionSynchronizer'.");
var solutionSynchronizerField = syncVsType.GetField("Synchronizer", BindingFlags.Static | BindingFlags.NonPublic);
ThrowIfNull(solutionSynchronizerField, "Field 'Synchronizer' is not found in 'SolutionSynchronizer'.");

var syncMethod = slnSynchronizerType.GetMethod("Sync", BindingFlags.Instance | BindingFlags.Public);
ThrowIfNull(syncMethod, "Method 'Sync' is not found in 'Synchronizer'.");
var syncMethod = slnSynchronizerType.GetMethod("Sync", BindingFlags.Instance | BindingFlags.Public);
ThrowIfNull(syncMethod, "Method 'Sync' is not found in 'Synchronizer'.");

syncMethod.Invoke(solutionSynchronizerField.GetValue(null), Array.Empty<object>());
syncMethod.Invoke(solutionSynchronizerField.GetValue(null), Array.Empty<object>());
}
else
{
// HACK: Make it look like a dummy file has been added.
CodeEditor.CurrentEditor.SyncIfNeeded(new [] { "RegenerateProjectFeature.cs" }, Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>(), Array.Empty<string>());
}
}
}

Expand Down

0 comments on commit 916d409

Please sign in to comment.