473,327 Members | 1,976 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Reflection to find the assemblies referenced by a C# project

Given a C# project file path, can I use reflection to get all the
assemblies referenced by the project?

e.g., I know the path of a C# project, say, "c:\SomeProject.csproj",
and I want to load its referenced assemblies to construct a list of
their members for display. Note that "c:\SomeProject.csproj" is not
the current project, it's just a project we're displaying information
about in the utility I'm trying to construct.

Nov 16 '05 #1
4 14446
..csproj files are XML. You can use XML to process this file. The issue that
you'll run into is loading project references as opposed to physical/assembly
references. You'll have to do work, to make sure the project reference is
built so that you can inspect it's types via reflection.
--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers
"Jimi" <ji************@yahoo-dot-ca.no-spam.invalid> wrote in message
news:40**********@127.0.0.1...
Given a C# project file path, can I use reflection to get all the
assemblies referenced by the project?

e.g., I know the path of a C# project, say, "c:\SomeProject.csproj",
and I want to load its referenced assemblies to construct a list of
their members for display. Note that "c:\SomeProject.csproj" is not
the current project, it's just a project we're displaying information
about in the utility I'm trying to construct.

Nov 16 '05 #2
I think it would be easier to parse the project file and extract this
information right from the data contained therein.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Jimi" <ji************@yahoo-dot-ca.no-spam.invalid> wrote in message
news:40**********@127.0.0.1...
Given a C# project file path, can I use reflection to get all the
assemblies referenced by the project?

e.g., I know the path of a C# project, say, "c:\SomeProject.csproj",
and I want to load its referenced assemblies to construct a list of
their members for display. Note that "c:\SomeProject.csproj" is not
the current project, it's just a project we're displaying information
about in the utility I'm trying to construct.


Nov 16 '05 #3
Thanks Justin and Dmitriy.

From your answers, and a little more digging, I think I'm going to do
the following:

1. parse the C# project file for the references (easy - done this
before)

2. search to see if the references have a built dll/exe somewhere

3. use something like:
"System.Reflection.Assembly asm =
System.Reflection.Assembly.LoadFrom(sPath);" to get load the
assemblies so I can examine its types and members (easy - done this
before)

1 & 3 are easy - I've done these sort of things before. But 2 is
a bit messy - if the reference is an assembly registered in the GAC,
then no problem (I just use the assembly name), but if the reference
is to another .NET project, then all the first "csproj" file will
tell me is the Name, Project, and Package of the referenced project -
none of these tell me where to find the other referenced project. Do
I then have to search for solution files that may have these ? This
just gets messier each step. Is there a more elegant way to do this
part?

Nov 16 '05 #4
Any ideas on part 2 of this?

I can get the assembly names of referenced C# project via the
GetReferencedAssemblies method on the Assembly object, but there
seems to be no way to get from the assembly name to an actual
assembly object (since it's not in the GAC), without knowing the
path. Do I need to scan entire drives to find the referenced
project's assembly dll? This seems a bit crazy - there must be an
easy way to get to the debug assemblies of referenced projects
without knowing the paths. Or, there must be an easy way to find the
path of a referenced project? (it's not in the "csproj" file, by the
way - it's in solution files, but this still leads to scanning drives
to find any solution files that may contain the C# project we're
interested in). This is driving me crazy.

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jozsef Bekes | last post by:
Hi All, I am trying to use reflection for getting all the classes from the dlls of a software written by my company. I am using this line: Assembly.LoadFile(s).GetTypes() Gettypes fails, I...
0
by: Jimi | last post by:
I'm working on a utility to provide an overview of one's .NET projects and one of the things I want to display is detailed information about what each project references, whether it is assemblies...
12
by: Antony | last post by:
Hello - I am wanting to print out a "Yes" next to classes that implement "Interface01", otherwise a "No". Here is my code. It crashes with a null reference exception and I am not sure why. Ideas?...
2
by: jnick | last post by:
I have the predicament of having to load several assemblies on the fly and when I do so, I get an exception stating that one of the referenced assemblies cannot be found. Is there any way to...
7
by: Allan Ebdrup | last post by:
How do I get hold of the type when I have a string that represents the type. For example I have the string "OFiR.Recruitment.Department" And I want to get the type called...
2
by: Jason | last post by:
Hello, I"m trying to invoke a method using reflection on a DLL that is already within a project. However, I"m having a few problems and didn't know if anyone has any bright ideas. Please note,...
6
by: Larry | last post by:
When compiling, i get the following error. Preparing resources... Updating references... Performing main compilation... vbc : error BC30145: Unable to emit assembly: Referenced assembly...
0
by: treefrog | last post by:
Greetings, I have a C# application that uses Reflection to scan through a directory, ./plugins/, for assemblies that have been assigned the PluginAttribute and loads them. This part works...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.