Saving .csproj files
- From: Al Pilon <al@xxxxxxxxxxx>
- Date: Fri, 16 Mar 2007 22:03:03 -0400
Any help would be appreciated for the following problem. I've already
spent a day at this, and enough is enough.
I'm writing a ORM program. and in the process of running it against a
database, I'm creating dozens of classes. I want to insert these
classes into the .csproj file automatically. I can do it just fine
manually, and I can do it also programatically up to the point that I
save the XmlDocument object. At that point, for some Redmond reason,
the XmlDocument.Save method insists on writing an xmlns="" attribute
to the node. This causes Visual Studio to puke upon trying to load the
project.
Here's the code that I use to add the node programatically
public Form1()
{
InitializeComponent();
XmlDocument doc = new XmlDocument();
string filename =
@"e:\Projects.NET\BB\BusinessBuilder.csproj";
doc.Load(filename);
XmlNode currentnode = doc.DocumentElement.FirstChild;
Boolean test = false;
do
{
currentnode = currentnode.NextSibling;
if (currentnode == null)
break;
if (currentnode.Name == "ItemGroup" &&
currentnode.FirstChild.Name == "Compile")
test = true;
} while (test == false);
if (test == true)
{
XmlElement elem = doc.CreateElement("Compile");
XmlAttribute att = doc.CreateAttribute("Include");
att.Value = @"DAL\test.cs";
elem.Attributes.Append(att);
currentnode.AppendChild(elem);
}
doc.Save(filename);
}
after the program runs, here is the line that it has inserted (in the
proper place)
<Compile Include="DAL\test.cs" xmlns="" />
and here is the error message that I receive when I try to load the
project
Unable to read the project file 'BusinessBuilder.csproj',
E:\Projects.NET\BB\BusinessBuilder.csproj (105,5):
The element <Compile> beneath element <ItemGroup> may
not have a custom XML namespace.
If I remove the xmlns="" manually, the project then opens fine.
All I can assume from my testing is that Microsoft must have something
else it uses to write to this file, since they apparently have no
problem doing the same thing if I add the class through the Solution
Explorer. If I can't get an answer, I'm going to be forced to treat
this thing as a plain text file, and add the lines in that way. That's
a hell of a way to deal with 'state-of-the-art' technology.
At any rate, any help would be appreciated. TIA.
.
- Follow-Ups:
- Re: Saving .csproj files
- From: Bjoern Hoehrmann
- Re: Saving .csproj files
- Prev by Date: Re: Trouble with XPath query
- Next by Date: Re: Saving .csproj files
- Previous by thread: Re: Redundant xmlns attribute
- Next by thread: Re: Saving .csproj files
- Index(es):
Relevant Pages
|