|
2 | 2 | // Licensed under the MIT License.
|
3 | 3 |
|
4 | 4 | using System.IO;
|
| 5 | +using System.Xml; |
5 | 6 | using UnityEngine;
|
6 | 7 |
|
7 | 8 | namespace Microsoft.MixedReality.Toolkit.Utilities.Editor
|
@@ -63,17 +64,49 @@ public static void EnsureLinkXml()
|
63 | 64 | {
|
64 | 65 | string generatedFolder = MixedRealityToolkitFiles.MapRelativeFolderPathToAbsolutePath(MixedRealityToolkitModuleType.Generated, "");
|
65 | 66 | string linkXmlPath = Path.Combine(generatedFolder, "link.xml");
|
| 67 | + |
66 | 68 | if (File.Exists(linkXmlPath))
|
67 | 69 | {
|
68 |
| - // Do not touch the existing file. |
| 70 | + bool xmlUpdated = false; |
| 71 | + |
| 72 | + // Update to ensure Unity's okay ignoring missing assemblies |
| 73 | + XmlDocument doc = new XmlDocument(); |
| 74 | + doc.Load(linkXmlPath); |
| 75 | + |
| 76 | + XmlNodeList assemblyNodes = doc.SelectNodes(@"/linker/assembly"); |
| 77 | + |
| 78 | + if (assemblyNodes != null) |
| 79 | + { |
| 80 | + XmlAttribute newAttr = doc.CreateAttribute("ignoreIfMissing"); |
| 81 | + newAttr.Value = "1"; |
| 82 | + |
| 83 | + foreach (XmlNode assembly in assemblyNodes) |
| 84 | + { |
| 85 | + XmlNode fullname = assembly.Attributes.GetNamedItem("fullname"); |
| 86 | + XmlNode ignoreIfMissing = assembly.Attributes.GetNamedItem("ignoreIfMissing"); |
| 87 | + if (ignoreIfMissing == null && fullname.InnerText.StartsWith("Microsoft.MixedReality.Toolkit")) |
| 88 | + { |
| 89 | + assembly.Attributes.SetNamedItem(newAttr); |
| 90 | + xmlUpdated = true; |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + |
| 95 | + if (xmlUpdated) |
| 96 | + { |
| 97 | + Debug.Log($"The link.xml file in {MixedRealityToolkitFiles.GetGeneratedFolder} was updated to include \"ignoreIfMissing\" tags.\n" + |
| 98 | + "This is required in Unity 2021 or later for legacy XR assemblies that are no longer used and is okay if this project is on an earlier version."); |
| 99 | + doc.Save(linkXmlPath); |
| 100 | + } |
| 101 | + |
69 | 102 | return;
|
70 | 103 | }
|
71 | 104 |
|
72 | 105 | // Create a default link.xml with an initial set of assembly preservation rules.
|
73 | 106 | using (StreamWriter writer = new StreamWriter(linkXmlPath))
|
74 | 107 | {
|
75 | 108 | writer.WriteLine(defaultLinkXmlContents);
|
76 |
| - Debug.Log($"A link.xml file was created in {MixedRealityToolkitFiles.GetGeneratedFolder}. \n" + |
| 109 | + Debug.Log($"A link.xml file was created in {MixedRealityToolkitFiles.GetGeneratedFolder}.\n" + |
77 | 110 | "This file is used to control preservation of MRTK code during linking. It is recommended to add link.xml (and link.xml.meta) to source control.");
|
78 | 111 | }
|
79 | 112 | }
|
|
0 commit comments