.net - How to delete a node in csproj file in c#? -


i want delete node <reference include="system.data" />

from csproj file programmatically. csproj file file structure :

<itemgroup>     <reference include="microsoft.csharp" />     <reference include="system.data.oracleclient" />     <reference include="system.messaging" />     <reference include="system.web.dynamicdata" />     <reference include="system.web.entity" />     <reference include="system.web.applicationservices" />     <reference include="system.componentmodel.dataannotations" />     <reference include="system" />     <reference include="system.data" />     <reference include="system.core" />     <reference include="system.data.datasetextensions" />     <reference include="system.web.extensions" />     <reference include="system.xml.linq" />     <reference include="system.drawing" />     <reference include="system.web" />     <reference include="system.xml" />     <reference include="system.configuration" />     <reference include="system.web.services" />     <reference include="system.enterpriseservices" />   </itemgroup> 

i'm trying code not working:

xmldocument doc = new xmldocument(); doc.load(fullfilepath); xmlnode node = doc.selectsinglenode(@"/project/itemgroup/reference[@include='system.data']");  node.parentnode.removechild(node);  doc.save(fullfilepath); 

easy xml linq

using system; using system.collections.generic; using system.linq; using system.text; using system.xml; using system.xml.linq;  namespace consoleapplication1 {     class program     {         static void main(string[] args)         {             string input =                 "<root>" +                     "<itemgroup>" +                         "<reference include=\"microsoft.csharp\" />" +                         "<reference include=\"system.data.oracleclient\" />" +                         "<reference include=\"system.messaging\" />" +                         "<reference include=\"system.web.dynamicdata\" />" +                         "<reference include=\"system.web.entity\" />" +                         "<reference include=\"system.web.applicationservices\" />" +                         "<reference include=\"system.componentmodel.dataannotations\" />" +                         "<reference include=\"system\" />" +                         "<reference include=\"system.data\" />" +                         "<reference include=\"system.core\" />" +                         "<reference include=\"system.data.datasetextensions\" />" +                         "<reference include=\"system.web.extensions\" />" +                         "<reference include=\"system.xml.linq\" />" +                         "<reference include=\"system.drawing\" />" +                         "<reference include=\"system.web\" />" +                         "<reference include=\"system.xml\" />" +                         "<reference include=\"system.configuration\" />" +                         "<reference include=\"system.web.services\" />" +                         "<reference include=\"system.enterpriseservices\" />" +                       "</itemgroup>" +                   "</root>";              xdocument doc = xdocument.parse(input);             list<xelement> itemgroup = doc.descendants("itemgroup").tolist();              itemgroup.elements("reference").where(x => x.attribute("include").value == "system.data").remove();         }     } } ​ 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -