加入我有這樣的代碼:刪除不需要的(空)xmlns屬性通過使用appendChild
function setupProject($projectFile) {
[xml]$root = Get-Content $projectFile;
$project = $root.Project;
$beforeBuild = $root.CreateElement("Target", "");
$beforeBuild.SetAttribute("name", "BeforeBuild");
$beforeBuild.RemoveAttribute("xmlns");
$project.AppendChild($beforeBuild);
$root.Save($projectFile);
}
它應該添加新<Target name="BeforeBuild" />
XML文檔。
但它也增加了一個空的xmlns=""
屬性,我不想要。 (它實際上是Visual Studio中不喜歡這個屬性!)
<Target name="BeforeBuild" xmlns="" />
我已經嘗試過這樣的代碼:
$beforeBuild.RemoveAttribute("xmlns");
$project.AppendChild($beforeBuild);
$beforeBuild.RemoveAttribute("xmlns");
感謝您的鏈接!第二種解決方案適用於我。您能否將該代碼片段插入到您的答案中?這對其他用戶會很有幫助。 – ComFreek
@ComFreek:不客氣!我更新了我的答案。 – Neolisk
不好的答案 - 它可能有用,但它表明了對問題原因的根本性誤解。 –