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