I have written a code generator, which generates C # files if the file is being generated, then I It requires adding a reference to our .csproj file. I have the following method that adds a node to a .csproj file.
Private Static Zero AddToProjectFile (string projectfilename, string projectfile interface) {StreamReader streamReader = new streamrider (projectFileName); XmlTextReader xmlReader = new XmlTextReader (streamer); XElement element; XNamespace namespace; // Load XML document XDocument xmlDoc = XDocument.Load (xmlReader); // Find the name of the XML name space Space = xmlDoc.Root.Name.Namespace; // Turn off the reader so that we can save the file back. StreamReader.Close (); // Create new element that we want to add. Element = new XElement (Namespace + "Compilation", New XAttribute ("Include", projectFileEntry)); // Add new element XmlDoc.Root.Elements (namespace + "item group"). Element (1). Add (element); XmlDoc.Save (projectFileName); }
This method works fine. However, it does not connect the node to a new line. This will add to the previous line in the .csproj file. TFS merge makes it a mess for you. How do I add a new node to a new line?
Why are you using streamreader and then XML text reader? Just pass the file name to XDocument.Load. Then everything works as you would expect, if you make the reader on your own XDocument, its settings can not be modified and thus the reader will report whitespace which is then stored in XLinq tree and when written It turns out that they disable automatic formatting in the author. So you can either ignore real locations on your reader, or pass input as a filename, which will allow XDocument to access your settings, which may be overlooked in the webspace.
As a side note, please use XmlTextReader, when you call XmlReader.Create, a more specific analog XML reader is created.
Comments
Post a Comment