我有这个代码:
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);
}
Run Code Online (Sandbox Code Playgroud)
它应该<Target name="BeforeBuild" />为XML文档添加一个新内容.
但它也添加了一个xmlns=""我不想要的空属性.(它实际上是Visual Studio,它不喜欢这个属性!)
<Target name="BeforeBuild" xmlns="" />
Run Code Online (Sandbox Code Playgroud)
我已经尝试过这段代码:
$beforeBuild.RemoveAttribute("xmlns");
$project.AppendChild($beforeBuild);
$beforeBuild.RemoveAttribute("xmlns");
Run Code Online (Sandbox Code Playgroud)