Methods to programmatically install a .NET assembly into the GAC
Asked Answered
K

2

10

I need to create a small app or script to install a .NET assembly into the GAC. I've read there are a couple ways to do this including:

  • using gacutil.exe
  • executing the following line of code:

    new System.EnterpriseServices.Internal.Publish().GACInstall("Foo.dll");

However, what would happen if I just created the appropriate directories on the machine and copied the assembly into that directory? The structure of the GAC directory is the following: C:\Windows\assembly\GAC_MSIL\Foo\<version#>__<public token>\Foo.dll

Do the above two methods do anything special besides creating the folder structure and placing the assembly into it?

Kish answered 22/9, 2009 at 15:30 Comment(3)
Before you experiment, make a backup.Caryophyllaceous
Revisiting this task recently, I abandoned the app/script idea for an MSI file instead. Nice and clean!Kish
Use GacInstall("Foo.dll") instead GACInstall("Foo.dll")Butylene
H
11

I strongly recommend using existing methods (like the ones you mentioned) because they are both supported and maintained by Microsoft and will continue to work with future releases.

A quick look at gacutil.exe with Process Monitor reveals that there is a little bit more to it than just copying files:

  • concurrency concerns (e.g. temporary files, locking WINDOWS\assembly\GACLock.dat, etc.)
  • notifications (e.g. HKLM\SOFTWARE\Microsoft\Fusion\GACChangeNotification\...)
  • indexing (e.g. HKLM\SOFTWARE\Microsoft\Fusion\NativeImagesIndex...)
  • validation (e.g. strong name, ...)

The wrapper in System.EnterpriseServices is very similar to this old blog post and should work just fine.

Harpp answered 22/9, 2009 at 17:23 Comment(0)
G
5

We recently had to do this for 10s of servers in an enterprise environment. We used Wix to build a very simple MSI (seriously - 5 minutes work) and published to all server (and dev boxes) through Group Policy.

Ginsberg answered 22/9, 2009 at 17:36 Comment(2)
Similar to what we did; we used Visual Studio to build the .msi installation project.Nonessential
Thanks. Ended up using the MSI approach.Kish

© 2022 - 2024 — McMap. All rights reserved.