以编程方式将 .NET 程序集安装到 GAC 中的方法

发布于 2024-08-05 06:21:58 字数 449 浏览 3 评论 0原文

我需要创建一个小型应用程序或脚本来将 .NET 程序集安装到 GAC 中。我读过有几种方法可以做到这一点,包括:

  • 使用 gacutil.exe
  • 执行以下代码行:

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

但是,如果我只是在计算机上创建适当的目录并将程序集复制到该目录中,会发生什么情况? GAC 目录的结构如下: C:\Windows\ assembly\GAC_MSIL\Foo\__\Foo.dll

以上两个方法执行任何操作除了创建文件夹结构并将程序集放入其中之外还有什么特别之处?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

聊慰 2024-08-12 06:21:58

强烈建议使用现有方法(如您提到的方法),因为它们均由 Microsoft 支持和维护,并将继续与未来版本一起使用。

使用进程监视器快速查看gacutil.exe a> 揭示了它不仅仅是复制文件:

  • 并发问题(例如临时文件、锁定WINDOWS\ assembly\GACLock.dat等)、
  • 通知(例如HKLM \SOFTWARE\Microsoft\Fusion\GACChangeNotification\...
  • 索引(例如 HKLM\SOFTWARE\Microsoft\Fusion\NativeImagesIndex...
  • 验证(例如强名称,...)

System.EnterpriseServices 中的包装器与这篇旧博客文章非常相似 并且应该可以正常工作。

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.

初见你 2024-08-12 06:21:58

最近,我们不得不对企业环境中的数十台服务器执行此操作。我们使用 Wix 构建了一个非常简单的 MSI(说真的 - 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文