SyncSolutionUtilities

This commit is contained in:
nakano yosuke 2020-04-14 01:16:38 +09:00
parent 0a37dcea9a
commit 450bc133b8
9 changed files with 165 additions and 10 deletions

View File

@ -10,7 +10,6 @@
<e p="AsmdefHelper.Example.Hoge.csproj" t="IncludeRecursive" /> <e p="AsmdefHelper.Example.Hoge.csproj" t="IncludeRecursive" />
<e p="AsmdefHelper.Example.Piyo.csproj" t="IncludeRecursive" /> <e p="AsmdefHelper.Example.Piyo.csproj" t="IncludeRecursive" />
<e p="AsmdefHelper.sln" t="IncludeFlat" /> <e p="AsmdefHelper.sln" t="IncludeFlat" />
<e p="Assembly-CSharp.csproj" t="IncludeRecursive" />
<e p="Assets" t="Include"> <e p="Assets" t="Include">
<e p="AsmdefHelper" t="Include"> <e p="AsmdefHelper" t="Include">
<e p="DependencyGraph" t="Include"> <e p="DependencyGraph" t="Include">
@ -44,12 +43,15 @@
<e p="AsmdefMultiEditWindow.cs" t="Include" /> <e p="AsmdefMultiEditWindow.cs" t="Include" />
</e> </e>
</e> </e>
<e p="SyncSolution" t="Include">
<e p="Editor" t="Include">
<e p="AsmdefHelper.SyncSolution.Editor.asmref" t="Include" />
<e p="SyncSolutionUtilities.cs" t="Include" />
</e>
</e>
<e p="Unity.InternalAPIEditorBridgeDev.001" t="Include"> <e p="Unity.InternalAPIEditorBridgeDev.001" t="Include">
<e p="Unity.InternalAPIEditorBridgeDev.001.asmdef" t="Include" /> <e p="Unity.InternalAPIEditorBridgeDev.001.asmdef" t="Include" />
</e> </e>
<e p="UnityInternalEditorAssembly" t="Include">
<e p="SyncSolutionUtilities.cs" t="Include" />
</e>
</e> </e>
</e> </e>
<e p="obj" t="ExcludeRecursive" /> <e p="obj" t="ExcludeRecursive" />

View File

@ -2,9 +2,9 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="f71251e0-52ab-4cea-859f-4c363c01a121" name="Default Changelist" comment=""> <list default="true" id="f71251e0-52ab-4cea-859f-4c363c01a121" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/.idea.AsmdefHelper/.idea/contentModel.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.AsmdefHelper/.idea/contentModel.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Assets/AsmdefHelper/Unity.InternalAPIEditorBridgeDev.001.meta" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/AsmdefHelper/Unity.InternalAPIEditorBridgeDev.001.meta" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/.idea.AsmdefHelper/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.AsmdefHelper/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Packages/manifest.json" beforeDir="false" afterPath="$PROJECT_DIR$/Packages/manifest.json" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Assets/AsmdefHelper/Unity.InternalAPIEditorBridgeDev.001/Unity.InternalAPIEditorBridgeDev.001.asmdef" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/AsmdefHelper/Unity.InternalAPIEditorBridgeDev.001/Unity.InternalAPIEditorBridgeDev.001.asmdef" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -15,8 +15,18 @@
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component> </component>
<component name="HighlightingSettingsPerFile"> <component name="HighlightingSettingsPerFile">
<setting file="file://$PROJECT_DIR$/Assets/AsmdefHelper/Unity.InternalAPIEditorBridgeDev.001/Unity.InternalAPIEditorBridgeDev.001.asmdef" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Assets/AsmdefHelper/DependencyGraph/Editor/AsmdefGraphView.cs" root0="FORCE_HIGHLIGHTING" /> <setting file="file://$PROJECT_DIR$/Assets/AsmdefHelper/DependencyGraph/Editor/AsmdefGraphView.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Assets/AsmdefHelper/Example/NewBehaviourScript.cs" root0="FORCE_HIGHLIGHTING" /> <setting file="file://$PROJECT_DIR$/Assets/AsmdefHelper/Example/NewBehaviourScript.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Assets/AsmdefHelper/SyncSolution/Editor/SyncSolutionUtilities.cs" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Assets/AsmdefHelper/DependencyGraph/Editor/AsmdefNode.cs" root0="FORCE_HIGHLIGHTING" />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/Assets/AsmdefHelper/SyncSolution/Editor/SyncSolutionUtilities.cs" />
</list>
</option>
</component> </component>
<component name="ProjectId" id="1aUVRj7P9hORuS7hmPgeR2JVC79" /> <component name="ProjectId" id="1aUVRj7P9hORuS7hmPgeR2JVC79" />
<component name="ProjectViewState"> <component name="ProjectViewState">
@ -72,6 +82,7 @@
<workItem from="1586792539676" duration="101000" /> <workItem from="1586792539676" duration="101000" />
<workItem from="1586793017650" duration="506000" /> <workItem from="1586793017650" duration="506000" />
<workItem from="1586793564564" duration="160000" /> <workItem from="1586793564564" duration="160000" />
<workItem from="1586793758449" duration="679000" />
</task> </task>
<servers /> <servers />
</component> </component>

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3343c43624a31f447a1961156a2cac6e
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 07e92c78d576a8a458ce4a298eeb512d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,3 @@
{
"reference": "GUID:211243abc45174c45b3a6c275ea126b9"
}

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 353d4308cc0c6c945a085f59650f2b11
AssemblyDefinitionReferenceImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using UnityEditor;
using UnityEngine;
//https://forum.unity.com/threads/solved-unity-not-generating-sln-file-from-assets-open-c-project.538487/
namespace EditorUtilities.Solution
{
public static class SyncSolutionUtilities
{
private static Type _syncVSType;
private static MethodInfo _syncSolutionMethodInfo;
private static FieldInfo _synchronizerField;
private static object _synchronizerObject;
private static Type _synchronizerType;
private static MethodInfo _synchronizerSyncMethodInfo;
static SyncSolutionUtilities()
{
_syncVSType = Type.GetType("UnityEditor.SyncVS,UnityEditor");
_synchronizerField = _syncVSType.GetField("Synchronizer", BindingFlags.NonPublic | BindingFlags.Static);
_syncSolutionMethodInfo = _syncVSType.GetMethod("SyncSolution", BindingFlags.Public | BindingFlags.Static);
_synchronizerObject = _synchronizerField.GetValue(_syncVSType);
_synchronizerType = _synchronizerObject.GetType();
_synchronizerSyncMethodInfo = _synchronizerType.GetMethod("Sync", BindingFlags.Public | BindingFlags.Instance);
}
[MenuItem("Assets/Sync C# Solution", priority = 1000000)]
public static void Sync()
{
Sync(true);
}
public static void Sync(bool logsEnabled)
{
CleanOldFiles(logsEnabled);
Call_SyncSolution(logsEnabled);
Call_SynchronizerSync(logsEnabled);
}
private static void CleanOldFiles(bool logsEnabled)
{
DirectoryInfo assetsDirectoryInfo = new DirectoryInfo(Application.dataPath);
DirectoryInfo projectDirectoryInfo = assetsDirectoryInfo.Parent;
IEnumerable<FileInfo> files = GetFilesByExtensions(projectDirectoryInfo, "*.sln", "*.csproj");
foreach(FileInfo file in files)
{
if(logsEnabled)
{
Debug.Log($"Remove old solution file: {file.Name}");
}
file.Delete();
}
}
private static void Call_SyncSolution(bool logsEnabled)
{
if(logsEnabled)
{
Debug.Log($"Coll method: SyncVS.Sync()");
}
_syncSolutionMethodInfo.Invoke(null, null);
}
private static void Call_SynchronizerSync(bool logsEnabled)
{
if(logsEnabled)
{
Debug.Log($"Coll method: SyncVS.Synchronizer.Sync()");
}
_synchronizerSyncMethodInfo.Invoke(_synchronizerObject, null);
}
private static IEnumerable<FileInfo> GetFilesByExtensions(DirectoryInfo dir, params string[] extensions)
{
extensions = extensions ?? new []{"*"};
IEnumerable<FileInfo> files = Enumerable.Empty<FileInfo>();
foreach(string ext in extensions)
{
files = files.Concat(dir.GetFiles(ext));
}
return files;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e5785f4c5d9ed634799d54e96aabf408
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,3 +1,15 @@
{ {
"name": "Unity.InternalAPIEditorBridgeDev.001" "name": "Unity.InternalAPIEditorBridgeDev.001",
"references": [],
"includePlatforms": [
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
} }