Saving .csproj files

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.
.



Relevant Pages

  • Re: Windows/Office problem
    ... Champ secured a place in history by writing: ... > What a load of tosh. ... > That's the problem with newsgroups - anyone can stand up and pretend ...
    (uk.rec.motorcycles)
  • Re: Reference to a class that does not exist
    ... Specifically, I am writing a Java library and there is another library that has some very useful features, but I don't expect that other library to always be available. ... It should depend upon your main application source, but there should not be any opposite dependencies. ... To attempt to use the code, use Class.forName to load a root class, and create a single instance with Constructor.newInstance. ...
    (comp.lang.java.programmer)
  • Thanks - Will try
    ... I will try what you suggested after dinner and see if ... I'll be writing :-) ... >> two Data Adapters and fill the dataset with two tables, ... > Yes, when you load the form,load your data and create the datarelations. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Invoke Java from Excel
    ... I'd never done it with Excel but with several other programs: ... First you must reach "native" code in your program (writing vb, ... load your main class, ... It seems to me that there is an activeX that launch the JVM, ...
    (comp.lang.java.programmer)