Reputation: 1925
I add XmlElemnt to csproj file from another file:
//load the orginal file
XmlDocument xd = new XmlDocument();
xd.Load(fileName);
//load the csproj file to setting
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(project.FullName);
//copy a XmlNode from the orginal file
XmlNode copiedNode = xmlDoc.ImportNode(xd.SelectSingleNode(nodeName), true);
//add the XmlNode to the csproj file
xmlDoc.DocumentElement.InsertAfter(copiedNode,xmlDoc.GetElementsByTagName(nodeName).Item(0));
and the source code add automatically the attribute xmlns="" to the added node:
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'AAA|x86'" xmlns="">
I see a similar issue in the post: Remove xmlns=“” attribute when adding Reference element into csproj. The solution there is to add namespace, but I don't find how to add namespace to my code.
How can I do that? Or- Is there other way to avoid the adding of the xmlns attribute?
Upvotes: 3
Views: 748
Reputation: 490
There are two possible solutions for you:
The first one is to set namespace of the root node of original file:
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'AAA|x86'" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
In this case the original element's namespace will be the same as destination root namespace and the xmlns attribute will not be added.
If it is not possible, you need to change namespace in your program. But it is not allowed to modify loaded XNodes by design. It can help.
Upvotes: 1