Monday, October 12, 2009

Getting all reference of an Assembly

To get the assembly reference in a ASP.NET web application i found a recursive method that will read from the csproject file.
Import these namespace also
using
System.Xml.Linq;
 
public void LoadAssembly(string path)
{
int result=0;
XNamespace msbuild = "http://schemas.microsoft.com/developer/msbuild/2003";
XDocument projDefinition = XDocument.Load(path);
IEnumerable<string> references = projDefinition.Element(msbuild + "Project")
.Elements(msbuild +
"ItemGroup")
.Elements(msbuild +
"Reference")
.Elements(msbuild +
"Name")
.Select(refElem => refElem.Value);
foreach (string reference in references)
{

richTextBox1.AppendText(reference);

richTextBox1.AppendText(Environment.NewLine);

        }
}
 
If you need to loop through the IEnumerable iterator to find out other xml nodes u can use the following
 
using (IEnumerator<string> enumerator = references.GetEnumerator())
{
while (enumerator.MoveNext())
result++;
}
if (result == 0)
{
//Do ur xml operations

}

0 comments: