| | 1 | | using System; |
| | 2 | | using System.IO; |
| | 3 | | using System.Xml.Linq; |
| | 4 | | using Packages.Rider.Editor; |
| | 5 | | using UnityEditor; |
| | 6 | |
|
| | 7 | | /// <summary> |
| | 8 | | /// Setup csproj files for DocFx on CI environment (docker). |
| | 9 | | /// <para /> |
| | 10 | | /// Run on cli: `-executeMethod DocFxForUnity.SetupCsProj` |
| | 11 | | /// </summary> |
| | 12 | | public static class DocFxForUnity |
| | 13 | | { |
| | 14 | | private const string k_DstDir = "Library/DocFxAssemblies"; |
| | 15 | |
|
| | 16 | | /// <summary> |
| | 17 | | /// Setup csproj files for DocFx on CI environment (docker). |
| | 18 | | /// Generate csproj files and copy dlls to 'Library/DocFxAssemblies' in project. |
| | 19 | | /// </summary> |
| | 20 | | public static void SetupCsProj() |
| 1 | 21 | | { |
| 1 | 22 | | Console.WriteLine($"[Coffee.DocFxForUnity.SetupCsProj]"); |
| | 23 | |
|
| | 24 | | // Generate solution and project file. |
| 1 | 25 | | Console.WriteLine($" -> Generate solution and project files (RiderScriptEditor)"); |
| 1 | 26 | | RiderScriptEditor.SyncSolution(); |
| | 27 | |
|
| | 28 | | // Delete local old dlls. |
| 1 | 29 | | Console.WriteLine($" -> Delete local old dlls"); |
| 1 | 30 | | if (Directory.Exists(k_DstDir)) |
| 1 | 31 | | { |
| 1 | 32 | | Directory.Delete(k_DstDir, true); |
| 1 | 33 | | } |
| | 34 | |
|
| 1 | 35 | | Directory.CreateDirectory(k_DstDir); |
| | 36 | |
|
| | 37 | | // Copy dlls to local. |
| 9 | 38 | | foreach (var csprojPath in Directory.GetFiles(".", "*.csproj")) |
| 3 | 39 | | { |
| 3 | 40 | | CopyDllsForCsProj(csprojPath); |
| 3 | 41 | | } |
| 1 | 42 | | } |
| | 43 | |
|
| | 44 | | private static void CopyDllsForCsProj(string csprojPath) |
| 3 | 45 | | { |
| 3 | 46 | | Console.WriteLine($" -> Copy dlls for: {csprojPath}"); |
| 3 | 47 | | var xml = XDocument.Load(csprojPath); |
| 2877 | 48 | | foreach (var e in xml.Descendants()) |
| 1434 | 49 | | { |
| | 50 | | // Already copied -> skip. |
| 2243 | 51 | | if (e.Name.LocalName != "HintPath" || e.Value.StartsWith(k_DstDir)) continue; |
| | 52 | |
|
| | 53 | | // Copy dlls. |
| 625 | 54 | | var src = e.Value; |
| 625 | 55 | | var dst = $"{k_DstDir}/{Path.GetFileName(src)}"; |
| | 56 | |
|
| | 57 | | // Copy dll files. |
| 625 | 58 | | CopyFile(src, dst); |
| | 59 | |
|
| | 60 | | // Copy xml files. |
| 625 | 61 | | CopyFile(Path.ChangeExtension(src, ".xml"), Path.ChangeExtension(dst, ".xml")); |
| | 62 | |
|
| | 63 | | // Change HintPath value. |
| 625 | 64 | | e.Value = dst; |
| 625 | 65 | | } |
| | 66 | |
|
| 3 | 67 | | xml.Save(csprojPath); |
| 3 | 68 | | } |
| | 69 | |
|
| | 70 | | private static void CopyFile(string src, string dst) |
| 1250 | 71 | | { |
| 2181 | 72 | | if (!File.Exists(src) || File.Exists(dst)) return; |
| | 73 | |
|
| 319 | 74 | | Console.WriteLine($" - {Path.GetFileName(dst)}"); |
| 319 | 75 | | File.Copy(src, dst); |
| 1250 | 76 | | } |
| | 77 | | } |