Methods to programmatically install a .NET assembly into the GAC

前端 未结 2 1746
借酒劲吻你
借酒劲吻你 2021-01-02 05:20

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.e
2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-02 06:22

    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.

提交回复
热议问题