none
Detect if My Own Assembly is installed... RRS feed

  • Question

  • I have an assembly that is to be installed in the GAC.  even though the phsyical location of the GAC is a folder, it isn't treated as such by windows.  So I can't simply do a:

    dir/s C:\Windows\assembly\GAC\*.*

    So how the ... ahem, how can i programmitically detect for the presence of a specific Assembly in the GAC?

    Thanks
    Jaeden "Sifo Dyas" al'Raec Ruiner

    (this is for a Prerequisite test application for an Installer)

    "Never Trust a computer. Your brain is smarter than any micro-chip."
    Tuesday, June 23, 2009 8:22 PM

Answers

All replies

  • try this:

    http://www.eggheadcafe.com/conversation.aspx?messageid=32079396&threadid=32079348

    Basically, here's how the code can easily be added to your application:


    Assembly assm = null;
    if (((assm = Assembly.LoadWithPartialName("System")) != null) && assm.GlobalAssemblyCache)
    {
        // exists in GAC.
    }

    Where "System" is replaced by the name of your assembly.

    David Morton - http://blog.davemorton.net/ - @davidmmorton - ForumsBrowser, a WPF MSDN Forums Client
    Tuesday, June 23, 2009 8:29 PM
    Moderator
  • Hey guys,

    Could be an easier way (although it was David's code that lead me to this) ... you should be able to do this from within the assembly thats running. The only thing with David's code is it needs to load the assembly (and it might put it to a different context) and perhaps the situation calls for that this code won't load the assembly.


    www.dsmyth.net | www.dsmyth.net/wiki
    Tuesday, June 23, 2009 9:14 PM
  • lost the formatting

    Assembly.GetExecutingAssembly().GlobalAssemblyCache 

    www.dsmyth.net | www.dsmyth.net/wiki
    Tuesday, June 23, 2009 9:15 PM
  • lost the formatting

    Assembly.GetExecutingAssembly().GlobalAssemblyCache 

    www.dsmyth.net | www.dsmyth.net/wiki

    That works great if the assembly you're trying to determine is the currently running assembly, but the OP stated that this is a prerequisite test for an installer, so I'm assuming two things:

    1) The installer will quit executing when finished, so loading the assembly into the AppDomain should cause minimal damage. 
    2) The Assembly he's trying to test is separate from the one testing it's existence.

    Derek, one more thing... check your post. Seems you may have malformed HTML in your first post. Everything's coming up blue.
    David Morton - http://blog.davemorton.net/ - @davidmmorton - ForumsBrowser, a WPF MSDN Forums Client
    Tuesday, June 23, 2009 9:18 PM
    Moderator
  • Hey Dave,

    No worries mate, your right, my mistake. The formatting is completely messed up this post.
    www.dsmyth.net | www.dsmyth.net/wiki
    Tuesday, June 23, 2009 9:24 PM