I'm trying to create an XML file using C# and Linq to XML, but am having problems with the nant namespace.
var myXElement = new XElement("project", new XAttribute("name", "MySystemName"), new XAttribute("default", "myNAntTargetName"), new XAttribute("xmlns", "http://nant.sf.net/schemas/nant.xsd"));
myXElement.Save("c:\foo.xml");
Because I'm trying to force-in the namespace XAtrribute (to http://nant.sf.net/schemas/nant.xsd) the .Save fails, saying:
XmlException Unhandled: The prefix '' cannot be redefined from '' to 'http://nant.sf.net/schemas/nant.xsd' within the same start element tag.
If I simply remove the namespace attribute, the file saves fine, but I need the namespace in there, as otherwise my NAnt commands fail.
Any suggestions?