I have this code:
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);
}
It should add a new <Target name="BeforeBuild" />
to the XML document.
But it also adds an empty xmlns=""
attribute which I don't want.
(It's actually Visual Studio which doesn't like this attribute!)
<Target name="BeforeBuild" xmlns="" />
I've already tried this code:
$beforeBuild.RemoveAttribute("xmlns");
$project.AppendChild($beforeBuild);
$beforeBuild.RemoveAttribute("xmlns");
<Project>
has one:xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
. So should I pass this value toCreateElement()
? – Weizmann