저는 csproj 파일의 어셈블리 이름을 변경할 유틸리티를 작성하고 있습니다. XPath가 잘 작동 할 수 있도록 csproj가 본질적으로 XML이라는 것을 알고 있습니다. 사실, 나는 특정 정보에 대해 작동하도록 할 수 있습니다. 내가 가지고있는 코드는 다음과 같습니다.코드에서 CSProj의 AssemblyName을 변경하십시오.
var xmlDoc = new XmlDocument();
xmlDoc.Load(file);
XmlNamespaceManager mgr = new XmlNamespaceManager(xmlDoc.NameTable);
mgr.AddNamespace("x", xmlDoc.DocumentElement.NamespaceURI);
XmlNode node = xmlDoc.SelectSingleNode("//x:PropertyGroup//AssemblyName", mgr);
node.Value = newValue;
xmlDoc.Save(file);
그러나, node
은 null입니다. 나는 또한 아무 쓸모가 "//x:PropertyGroup[1]//AssemblyName"
를 사용하여 시도했다. 방금 시도하고 찾을 경우 "//x:PropertyGroup"
잘 작동합니다, 그래서 모든 PropertyGroup 노드 AssemblyName 노드가 내 문제는 가정 해요.
this thread의 제안에 따라 NamespaceManager를 사용 중이며 here과 같이 XLinq을 통해 AssemblyName 값을 가져올 수 있었지만 값을 업데이트해야합니다.
무엇이 누락 되었습니까?
그냥 추측해도 AssemblyName은이 XPath에서 x로 표시된 네임 스페이스에도 포함되지 않습니다. // x : PropertyGroup // AssemblyName. 나는. (데이터를 알지 못한다면) // x : PropertyGroup // x : AssemblyName – dkackman
예, 그랬 겠지요. 또한, 나는 단지'node.Value'를 할 수없고,'node.FirstChild.Value'를 할 필요가 있습니다. 감사합니다. – Devin