|
| 1 | +#if ENABLE_VSTU |
| 2 | +using UnityEditor; |
| 3 | +using SyntaxTree.VisualStudio.Unity.Bridge; |
| 4 | + |
| 5 | +/// <summary> |
| 6 | +/// This class hooks into the Visual Studio .sln generation step and modifies the file |
| 7 | +/// to include .editorconfig, which enforces consistent formatting standards and naming |
| 8 | +/// conventions. |
| 9 | +/// https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017 |
| 10 | +/// </summary> |
| 11 | +[InitializeOnLoad] |
| 12 | +public class EditorConfigSolutionFileGenerator |
| 13 | +{ |
| 14 | + public static string kEditorConfigProjectFindStr = "EndProject\r\nGlobal"; |
| 15 | + public static string kEditorConfigProjectReplaceStr = |
| 16 | + "EndProject\r\n" + |
| 17 | + "Project(\"{2150E333-8FDC-42A3-9474-1A3956D46DE8}\") = \"Solution Items\", \"Solution Items\", \"{B24FE069-BB5F-4F16-BCDA-61C28EABC46B}\"\r\n" + |
| 18 | + " ProjectSection(SolutionItems) = preProject\r\n" + |
| 19 | + " .editorconfig = .editorconfig\r\n" + |
| 20 | + " EndProjectSection\r\n" + |
| 21 | + "EndProject\r\n" + |
| 22 | + "Global"; |
| 23 | + |
| 24 | + public static string kGlobalSectionFindStr = "EndGlobalSection\r\nEndGlobal"; |
| 25 | + public static string kGlobalSectionReplaceStr = |
| 26 | + "EndGlobalSection\r\n" + |
| 27 | + " GlobalSection(ExtensibilityGlobals) = postSolution\r\n" + |
| 28 | + " SolutionGuid = {FD87994B-C032-4821-BD72-E057C33083EF}\r\n" + |
| 29 | + " EndGlobalSection\r\n" + |
| 30 | + "EndGlobal"; |
| 31 | + |
| 32 | + static EditorConfigSolutionFileGenerator() |
| 33 | + { |
| 34 | + ProjectFilesGenerator.SolutionFileGeneration += AppendEditorConfig; |
| 35 | + } |
| 36 | + |
| 37 | + protected static string AppendEditorConfig(string fileName, string fileContent) |
| 38 | + { |
| 39 | + fileContent = fileContent.Replace( kEditorConfigProjectFindStr, kEditorConfigProjectReplaceStr ); |
| 40 | + fileContent = fileContent.Replace( kGlobalSectionFindStr, kGlobalSectionReplaceStr ); |
| 41 | + |
| 42 | + return fileContent; |
| 43 | + } |
| 44 | +} |
| 45 | +#endif |
0 commit comments