none
How to load all the Assemblies referenced by a console or winform app? RRS feed

  • Question

  • Hi all,

    Just like what we can do for ASP.NET——there's a nice way called "BuildManager.GetReferencedAssemblies()" to fetch all the referenced libraries (no matter they are used or loaded in the app domain or not).

    But how to do in a console or winform app?


    Reproduce your quesions with ScreenToGif is your choice.
    For IIS: IIS Forum,
    For WebSite of .NET: ASP.NET Forum,
    For others: StackExchange.
    For spam-sender or forum urgent issues, Send your Email at:  forumsfeedback@microsoft.com

    Saturday, December 30, 2017 2:11 PM

All replies

  • Check this:

    var d = AppDomain.CurrentDomain;
    foreach( var a in d.GetAssemblies() )
    {
       Console.WriteLine( a.FullName );
       foreach( var an in a.GetReferencedAssemblies() )
       {
          Console.WriteLine( "\t" + an.Name );
       }
    }

    But it will not always show all of the references that can be seen in Solution Explorer, probably because that information is for Compiler and is not embedded into programs. If you create some other objects (for example: ‘new XmlDocument()’) before or after the above loops), then the list will include more assemblies.





    Saturday, December 30, 2017 3:59 PM
  • Yes, that's just the problem……Can we make something like "BuildManager" in ASP.NET for a console or winform app?

    Reproduce your quesions with ScreenToGif is your choice. 
    For IIS: IIS Forum
    For WebSite of .NET: ASP.NET Forum
    For others: StackExchange
    For spam-sender or forum urgent issues, Send your Email at:  forumsfeedback@microsoft.com

    Sunday, December 31, 2017 1:04 AM
  • Hi ThankfulHeart,

    Thank you for posting here.

    >>Can we make something like "BuildManager" in ASP.NET for a console or winform app?

    As I know, the collection of assemblies that is returned from the GetReferencedAssemblies method includes assemblies specified in the element of the Web.config file.  The Console, Winform app use App.config file. It is not suitable.

    Best Regards,

    Wendy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Monday, January 1, 2018 6:36 AM
    Moderator