XMLFile.AddElement adds xlmns attribute to element

Jan 13, 2010 at 2:25 PM

I am trying to modify a C# csproj file to add a filename reference to a build.

The XMLFile.AddElement will add the element and the Include attribute but it also adds an additional xlmns="" attribute which breaks the build.

Here is how I have used XMLFile.AddElement.

  <Target Name="AddElement3">
      <ItemNamespaces Include="MSBuild">

and here is how the resulting Reference element appears:

    <Reference Include="CorvusImageViewer.dll" xmlns="" />

What am I doing wrong here?

What do I need to do to avoid xmlns=""? 

Any help would be appreciated.


Jan 13, 2010 at 3:11 PM
Edited Jan 13, 2010 at 4:52 PM

After a bit more playing about, I found that any new element will get the xmlns="" attribute regardless of whether you use the KeyAttributeName attribute.

Not only that but if I use XMLFile.DeleteAttribute task to delete the xmlns="", it says it finds the elements and deletes the attribute but on inspection the xmlns="" is still there. This leads me to believe that when the updated element is written back out the xmlns="" is put back.

This can't be right.


Jan 14, 2010 at 12:33 PM

Apparently, according to http://stackoverflow.com/questions/1305833/xmlmassupdate-how-not-to-add-xmlns, this cannot be avoided.

I'll just have to mung up the solution with some file post processing to remove the xlmns.