This repository was archived by the owner on Oct 9, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathAutoAddUnityEngineAnalyzer.cs
More file actions
68 lines (56 loc) · 2.49 KB
/
AutoAddUnityEngineAnalyzer.cs
File metadata and controls
68 lines (56 loc) · 2.49 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using UnityEditor;
using UnityEngine;
using System.IO;
using System.Xml.Linq;
using System.Linq;
namespace UnityEngineAnalyzer
{
public class AutoAddUnityEngineAnalyzer : AssetPostprocessor
{
/// <summary>
/// Put your UnityEngineAnalyzer.dll in your unity project,
/// and modify this path relative to your project.
/// </summary>
public const string UnityEngineAnalyzerPath = "Tools\\VisualStudio\\UnityEngineAnalyzer\\UnityEngineAnalyzer.dll";
static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
{
TryAddUnityEngineAnalyzer();
}
private static void TryAddUnityEngineAnalyzer()
{
string dataPath = Application.dataPath + "/../";
var csprojPaths = Directory.GetFiles(dataPath, "*.csproj");
foreach(var oneCsProjPath in csprojPaths)
{
if(!string.IsNullOrEmpty(oneCsProjPath))
{
XDocument doc = XDocument.Load(oneCsProjPath);
var defaultNamespace = doc.Root.GetDefaultNamespace();
var unityEngineAnalyzer = doc.Descendants(defaultNamespace + "Analyzer").
Where(x => x.Attribute("Include").
Value.Contains("UnityEngineAnalyzer.dll")).
FirstOrDefault();
if(unityEngineAnalyzer == null)
{
Debug.Log("can not find UnityEngineAnalyzer in oneCsProjPath=" + oneCsProjPath);
try
{
doc.Root.
Add(
new XElement(defaultNamespace + "ItemGroup",
new XElement(defaultNamespace + "Analyzer",
new XAttribute("Include", UnityEngineAnalyzerPath))));
doc.Save(oneCsProjPath);
Debug.Log("did add UnityEngineAnalyzer in oneCsProjPath=" + oneCsProjPath);
}
catch (System.Exception ex)
{
Debug.LogError("exception caught in adding UnityEngineAnalyzer in oneCsProjPath=" + oneCsProjPath + "\nexception=" + ex);
}
}
}
}
}
}
}