Quantcast
Channel: XML, System.Xml, MSXML and XmlLite forum
Viewing all articles
Browse latest Browse all 935

add class file to project programatically using .csproj

$
0
0

 

Hi all,

i am trying to add class files programmatically by editing .csproj file using xml.

my code is like,

 

string classFile = txtNameSpace.Text.Trim() + ".cs";

            string path = @"D:\Cat-Load\Latest_POC_CatalystLoading\Automatic Master Screeen Generator\BusinessObjects\AMSGBusinessObjects\" + classFile;
            FileStream fs = new FileStream(path, FileMode.Create, FileAccess.ReadWrite);
            StreamWriter sw = new StreamWriter(fs);

            sw.Write(classFile);
            sw.Close();

 

            XmlDocument myXmlDocument = new XmlDocument();

            myXmlDocument.Load(filename);

 

            XmlTextReader reader = new XmlTextReader(filename);
            XmlDocument doc = new XmlDocument();


            doc.Load(reader);
            reader.Close();
            XmlNode currNode;

 

            XmlDocumentFragment docFrag = doc.CreateDocumentFragment();
            docFrag.InnerXml = "<ItemGroup>" +
                                "<Compile Include=\"" + classFile + "\">" + "</Compile>" + "</ItemGroup>";

            // insert the availability node into the document

            currNode = doc.DocumentElement;
            currNode.InsertAfter(docFrag, currNode.LastChild);


            //save the output to a file
            doc.Save(filename);

 

after saving .csproj file, If i open csproj file xmlns="" is added to <ItemGroup> that i haven't added.

example:
<ItemGroup xmlns="">
    <Compile Include="test.cs">
    </Compile>
  </ItemGroup>

Manually if i remove xmlns="" from csproj. Then it works fine

Please help me. Ur help will be apprciated


Viewing all articles
Browse latest Browse all 935

Trending Articles