将 DLL 拖放到 Windows Server 2008 .net 4.0 中的 GAC(“程序集”)
我试图将一些代码部署到客户端计算机,但我不想在客户端计算机上安装 MS Windows SDK 工具。这意味着无权访问“gacutil”。我还没有为我的代码创建安装程序。看起来这可能是 .net 4.0 中仅有的两个选项。
过去,我只是简单地开始、运行、输入“程序集”,然后将我的 dll 拖放到其中。
这不再可能了吗?当我尝试执行此操作时,我没有收到错误消息,但 dll 没有出现在“程序集”文件夹中。当我在我的开发机器上使用 gacutil 时,它可以正常工作,但 dll 仍然没有出现。
I've trying to deploy some code to a client machine, where I don't want to install MS windows SDK tools. This means don't have access to "gacutil". I also have not created an installer for my code. It seems that these might be the only two options in .net 4.0.
In the past I would simply go to start, run, type "assembly", and drag and drop my dll in.
Is this no longer possible? When I try to do this I get no error message, but the dll doesn't appear in the "assembly" folder. When I use gacutil on my dev machine it works properly, but the dll still doesn't appear.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
在 .net 4.0 中,Microsoft 取消了仅通过拖放即可将 DLL 添加到程序集的功能。
相反,您需要使用 gacutil.exe,或创建一个安装程序来执行此操作。微软实际上不建议使用 gacutil,但我还是走了那条路。
要在开发计算机上使用 gacutil,请转至:
开始 ->程序->微软 Visual Studio 2010 -> Visual Studio 工具 -> Visual Studio 命令提示符(2010)
然后使用这些命令分别卸载和重新安装。请注意,我没有在卸载命令中包含
.dll
。gacutil /u myDLL
gacutil /i "C:\Program Files\Custom\myDLL.dll"
要在非开发计算机上使用 Gacutil,您必须将可执行文件和配置文件从开发计算机复制到生产计算机。看起来 Gacutil 有几个不同的版本。我在这里找到了对我有用的一个:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\gacutil.exe
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\gacutil.exe.config
将文件复制到此处或相应的 .net 文件夹中;
C:\Windows\Microsoft.NET\Framework\v4.0.30319
然后分别使用这些命令卸载并重新安装
“C:\Users\BHJeremy\Desktop\安装到 .net 4.0\gacutil.exe 中的 Gac”/u“myDLL”
“C:\Windows\Microsoft.NET\Framework\ v4.0.30319\gacutil.exe" /i "C:\Program Files\Custom\myDLL.dll"
In .net 4.0 Microsoft removed the ability to add DLLs to the Assembly simply by dragging and dropping.
Instead you need to use gacutil.exe, or create an installer to do it. Microsoft actually doesn’t recommend using gacutil, but I went that route anyway.
To use gacutil on a development machine go to:
Start -> programs -> Microsoft Visual studio 2010 -> Visual Studio Tools -> Visual Studio Command Prompt (2010)
Then use these commands to uninstall and Reinstall respectively. Note I did NOT include
.dll
in the uninstall command.gacutil /u myDLL
gacutil /i "C:\Program Files\Custom\myDLL.dll"
To use Gacutil on a non-development machine you will have to copy the executable and config file from your dev machine to the production machine. It looks like there are a few different versions of Gacutil. The one that worked for me, I found here:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\gacutil.exe
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\gacutil.exe.config
Copy the files here or to the appropriate .net folder;
C:\Windows\Microsoft.NET\Framework\v4.0.30319
Then use these commands to uninstall and reinstall respectively
"C:\Users\BHJeremy\Desktop\Installing to the Gac in .net 4.0\gacutil.exe" /u "myDLL"
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\gacutil.exe" /i "C:\Program Files\Custom\myDLL.dll"
在可能的情况下,我需要复制 gacutil.exe、gacutil.exe.config 以及 gacutilrc.dll(来自 1033 目录)
In may case, I nedded to copy the gacutil.exe, gacutil.exe.config AND ALSO the gacutlrc.dll (from the 1033 directory)
gacutil
实用程序在客户端计算机上不可用,并且 Window SDK 许可证禁止将其重新分发给您的客户。当您的客户不能、不会(而且确实不应该)下载 300MB Windows SDK 作为应用程序安装过程的一部分时。您(或您的安装程序)可以使用官方支持的 API 在全局程序集缓存中注册程序集。 Microsoft 的 Windows Installer 技术知道如何为您调用此 API。您必须咨询 MSI 安装程序实用程序(例如 WiX、InnoSetup),了解它们自己的语法,了解如何指示您希望在全局程序集缓存中注册程序集。
但 MSI 和 gacutil 并没有做任何特别的事情。他们只是调用您自己可以调用的相同 API。有关如何通过代码注册程序集的文档,请参阅:
删除知识库文章之前的更多文档:
The
gacutil
utility is not available on client machines, and the Window SDK license forbids redistributing it to your customers. When your customer can not, will not, (and really should not) download the 300MB Windows SDK as part of your application's install process.There is an officially supported API you (or your installer) can use to register an assembly in the global assembly cache. Microsoft's Windows Installer technology knows how to call this API for you. You would have to consult your MSI installer utility (e.g. WiX, InnoSetup) for their own syntax of how to indicate you want an assembly to be registered in the Global Assembly Cache.
But MSI, and gacutil, are doing nothing special. They simply call the same API you can call yourself. For documentation on how to register an assembly through code, see:
More documentation before the KB article is deleted:
如果您安装了必要的
.net
框架。前任 ;.Net 4.0
或.Net 3.5
,那么您只需将Gacutil.exe
从任何计算机复制到新计算机即可。1) 在新服务器中以管理员身份打开CMD。
2) 遍历到复制 Gacutil.exe 的文件夹。例如 - C:\program files。(就我而言)。
3) 在cmd提示符中输入以下内容并安装。
if you have neccessary
.net
framework installed. Ex ;.Net 4.0
or.Net 3.5
, then you can just copyGacutil.exe
from any of the machine and to the new machine.1) Open CMD as adminstrator in new server.
2) Traverse to the folder where you copied the Gacutil.exe. For eg - C:\program files.(in my case).
3) Type the below in the cmd prompt and install.
安装程序和 gacutil 的其他替代品是 GUI 工具,例如 Gac Manager 或 GACAdmin。或者,如果您喜欢 PowerShell,您可以使用我作为作者的 PowerShell GAC。
Other alternatives to an installer and gacutil are GUI tools like Gac Manager or GACAdmin. Or if you like PowerShell you could use PowerShell GAC from which I am the author.
请记住,Fusion API 是非托管的。它的当前参考位于:开发指南 >非托管 API 参考 > Fusion
但是,有一种托管方法可以将程序集添加到 GAC:
System.EnterpriseServices.Internal.Publish.GacInstall
而且,如果您需要注册任何类型:
System.EnterpriseServices.Internal.Publish.RegisterAssembly
发布类的参考位于:.NET Framework 类库> System.EnterpriseServices 命名空间 > System.EnterpriseServices.Internal
但是,这些方法是为安装 Web 服务应用程序(例如 ASP.NET 或 WCF)所需的组件而设计的。因此,他们不会向 Fusion 注册程序集;因此,它们可以被其他应用程序卸载,或者使用 gacutil 并导致程序集停止工作。因此,如果您在管理员管理 GAC 的 Web 服务器之外使用它们,请务必在 SOFTWARE\Wow6432Node\Microsoft\Fusion\References(对于 64 位操作系统)或 SOFTWARE\Microsoft\ 中添加对您的应用程序的引用Fusion\References(适用于 32 位操作系统),以便没有人可以删除您的支持程序集,除非他们卸载您的应用程序。
Keep in mind that the Fusion API is unmanaged. The current reference for it is here: Development Guide > Unmanaged API Reference > Fusion
However, there is a managed method to add an assembly to GAC:
System.EnterpriseServices.Internal.Publish.GacInstall
And, if you need to register any Types:
System.EnterpriseServices.Internal.Publish.RegisterAssembly
The reference for the publish class is here: .NET Framework Class Library > System.EnterpriseServices Namespaces > System.EnterpriseServices.Internal
However, these methods were designed for installing components that are required by a web service application such as ASP.NET or WCF. As a result they don't register the assemblies with Fusion; thus, they can be uninstalled by other applications, or using gacutil and cause your assembly to stop working. So, if you use them outside of a web server where an administrator is managing the GAC then be sure to add a reference to your application in SOFTWARE\Wow6432Node\Microsoft\Fusion\References (for 64-bit OS) or SOFTWARE\Microsoft\Fusion\References (for 32-bit OS) so that nobody can remove your support assemblies unless they uninstall your application.
您还可以使用命令提示符将文件复制到 GAC。我使用以下批处理脚本复制 DLL 并重新启动 IIS。
无需使用或安装 gacutil
You can also just copy the file to GAC using a command prompt. I use the following batch script to copy the DLL and restart IIS.
Saves the need to use or install gacutil