xml - Parse csproj via c# - cannot parse ItemGroup -


i try dll names csproj file, cannot anything! so,i try al elements itemgroup tag liq query:

 var elem = doc.descendants("project").where(t => t.attribute("toolsversion")!=null)                 .elements("itemgroup").elements("reference").where(r => r.attribute("include") != null);             var attrs = elem.attributes();             console.writeline(attrs.count());             foreach (var e in attrs)             {                 console.writeline(e);             } 

and xml csproj file. cut unusfull text))

<?xml version="1.0" encoding="utf-8"?> <project toolsversion="4.0" defaulttargets="build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">   <applicationicon>icon.ico</applicationicon>  </propertygroup> <itemgroup> <reference include="system" /> <reference include="system.componentmodel.composition" /> <reference include="system.data" /> <reference include="system.drawing" /> <reference include="system.xml" /> <reference include="microsoft.csharp" /> <reference include="system.core" /> <reference include="system.xml.linq" /> <reference include="system.data.datasetextensions" /> <reference include="system.xaml">     <requiredtargetframework>4.0</requiredtargetframework> </reference> <reference include="myproject1" /> <reference include="myproject2" /> <reference include="myproject3" />  </itemgroup>  </project> 

please, me list of names! wrong?

thank you.

you're ignoring this:

xmlns="http://schemas.microsoft.com/developer/msbuild/2003" 

that sets default namespace descendants. want:

xnamespace ns = "http://schemas.microsoft.com/developer/msbuild/2003"; var elem = doc.descendants(ns + "project")                .where(t => t.attribute("toolsversion")!=null)               .elements(ns + "itemgroup")               .elements(ns + "reference")               .where(r => r.attribute("include") != null); 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -