以编程方式将 .NET 程序集安装到 GAC 中的方法
我需要创建一个小型应用程序或脚本来将 .NET 程序集安装到 GAC 中。我读过有几种方法可以做到这一点,包括:
- 使用
gacutil.exe
执行以下代码行:
new System.EnterpriseServices.Internal.Publish().GACInstall("Foo.dll");
但是,如果我只是在计算机上创建适当的目录并将程序集复制到该目录中,会发生什么情况? GAC 目录的结构如下: C:\Windows\ assembly\GAC_MSIL\Foo\
以上两个方法执行任何操作除了创建文件夹结构并将程序集放入其中之外还有什么特别之处?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我强烈建议使用现有方法(如您提到的方法),因为它们均由 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:WINDOWS\assembly\GACLock.dat
, etc.)HKLM\SOFTWARE\Microsoft\Fusion\GACChangeNotification\...
)HKLM\SOFTWARE\Microsoft\Fusion\NativeImagesIndex...
)The wrapper in
System.EnterpriseServices
is very similar to this old blog post and should work just fine.最近,我们不得不对企业环境中的数十台服务器执行此操作。我们使用 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.