I have this code:
function setupProject($projectFile) {
[xml]$root = Get-Content $projectFile;
$project = $root.Project;
$beforeBuild = $root.CreateE
As answered by Michael Kay, the best way to remove this unwanted namespace is creating the new child element in the same namespace as its parent:
function setupProject($projectFile) {
[xml]$root = Get-Content $projectFile;
$project = $root.Project;
# UPDATE THIS LINE $beforeBuild = $root.CreateElement("Target", "");
$beforeBuild = $root.CreateElement("Target", $project.NamespaceURI);
$beforeBuild.SetAttribute("name", "BeforeBuild");
$beforeBuild.RemoveAttribute("xmlns");
$project.AppendChild($beforeBuild);
$root.Save($projectFile);
}