void FindAllImports() { var xmlNamespaceManager = new XmlNamespaceManager(new NameTable()); xmlNamespaceManager.AddNamespace("ns", MSBuildFile.NamespaceName); XPathNavigator navigator = doc.CreateNavigator(); navigator.MoveToRoot(); var xpath = "/ns:Project/ns:Import[@Project]"; XPathExpression expr = navigator.Compile(xpath); expr.SetContext(xmlNamespaceManager); var nodeIterator = navigator.Select(expr); if (nodeIterator.Count == 0) { return; } while (nodeIterator.MoveNext()) { if (nodeIterator.Current is IHasXmlNode) { XmlNode node = ((IHasXmlNode)nodeIterator.Current).GetNode(); XmlElement element = (XmlElement)node; MSBuildImport wrapperObject = new MSBuildImport(this, element); importNodes.Add(wrapperObject); } } // see also https://weblogs.asp.net/cazzu/86609 }
public void InsertImportAfter(MSBuildImport existingImport, MSBuildImport newImport) { // запомнить у себя this.importNodes.Add(newImport); // вставить в нижележащий слой XmlElement existingElement = existingImport.UnderlyingObject; XmlElement newElement = newImport.UnderlyingObject; existingElement.ParentNode.InsertAfter(newElement, existingElement); bSaveRequired = true; }
public void InjectProjectImport(string import_name) { // construct new import MSBuildImport newImport = this.UnderlyingObject.CreateImport(); newImport.Project = import_name; // insert import MSBuildImport existingImport = this.UnderlyingObject.FindImport("$(MSBuildBinPath)\\Microsoft.CSharp.targets"); if (existingImport == null) { this.UnderlyingObject.InsertImport(newImport); } else { this.UnderlyingObject.InsertImportAfter(existingImport, newImport); } }
public void InsertImport(MSBuildImport newImport) { if (FindImport(newImport.Project) != null) { return; } // запомнить у себя this.importNodes.Add(newImport); // у тебя в руках узел, но оне вставленный в XML-документ XmlElement newXmlElement = newImport.UnderlyingObject; XPathNavigator navigator = doc.CreateNavigator(); navigator.MoveToRoot(); XmlNode root = (XmlNode)navigator.UnderlyingObject; XmlNode lc = root.LastChild; lc.AppendChild(newXmlElement); bSaveRequired = true; }
public static XmlElement GetKeyForItem(MSBuildImport item) { return(item.UnderlyingObject); }
public MSBuildImport CreateImport() { var result = new MSBuildImport(this); return(result); }