将 DLL 拖放到 Windows Server 2008 .net 4.0 中的 GAC(“程序集”)

发布于 2024-12-10 09:24:50 字数 269 浏览 5 评论 0原文

我试图将一些代码部署到客户端计算机,但我不想在客户端计算机上安装 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 技术交流群。

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

发布评论

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

评论(7

不一样的天空 2024-12-17 09:24:50

在 .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"

(り薆情海 2024-12-17 09:24:50

在可能的情况下,我需要复制 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)

白云不回头 2024-12-17 09:24:50

gacutil 实用程序在客户端计算机上不可用,并且 Window SDK 许可证禁止将其重新分发给您的客户。当您的客户不能、不会(而且确实不应该)下载 300MB Windows SDK 作为应用程序安装过程的一部分时。

您(或您的安装程序)可以使用官方支持的 API 在全局程序集缓存中注册程序集。 Microsoft 的 Windows Installer 技术知道如何为您调用此 API。您必须咨询 MSI 安装程序实用程序(例如 WiX、InnoSetup),了解它们自己的语法,了解如何指示您希望在全局程序集缓存中注册程序集。

但 MSI 和 gacutil 并没有做任何特别的事情。他们只是调用您自己可以调用的相同 API。有关如何通过代码注册程序集的文档,请参阅:

KB317540:DOC:全局程序集缓存 (GAC) API 未记录在 .NET Framework 软件开发工具包中(SDK)文档

var IAssemblyCache assemblyCache;
CreateAssemblyCache(ref assemblyCache, 0);


String manifestPath = "D:\Program Files\Contoso\Frobber\Grob.dll";

FUSION_INSTALL_REFERENCE refData;
refData.cbSize = SizeOf(refData); //The size of the structure in bytes
refData.dwFlags = 0; //Reserved, must be zero
refData.guidScheme = FUSION_REFCOUNT_FILEPATH_GUID; //The assembly is referenced by an application that is represented by a file in the file system. The szIdentifier field is the path to this file.
refData.szIdentifier = "D:\Program Files\Contoso\Frobber\SuperGrob.exe"; //A unique string that identifies the application that installed the assembly
refData.szNonCannonicalData = "Super cool grobber 9000"; //A string that is only understood by the entity that adds the reference. The GAC only stores this string

//Add a new assembly to the GAC. 
//The assembly must be persisted in the file system and is copied to the GAC.
assemblyCache.InstallAssembly(
      IASSEMBLYCACHE_INSTALL_FLAG_FORCE_REFRESH, //The files of an existing assembly are overwritten regardless of their version number
      manifestPath, //A string pointing to the dynamic-linked library (DLL) that contains the assembly manifest. Other assembly files must reside in the same directory as the DLL that contains the assembly manifest.
      refData);

删除知识库文章之前的更多文档:

该结构体的字段定义如下:

  • cbSize - 结构的大小(以字节为单位)。
  • dwFlags - 保留,必须为零。
  • guidScheme - 添加引用的实体。
  • szIdentifier - 标识安装程序集的应用程序的唯一字符串。
  • szNonCannonicalData - 只有添加引用的实体才能理解的字符串。 GAC 仅存储该字符串。

guidScheme 字段的可能值可以是以下之一:

FUSION_REFCOUNT_MSI_GUID - 该程序集由使用 Windows Installer 安装的应用程序引用。 szIdentifier 字段设置为 MSIszNonCannonicalData 设置为 Windows Installer。此方案只能由 Windows Installer 本身使用。
FUSION_REFCOUNT_UNINSTALL_SUBKEY_GUID - 该程序集由添加/删除程序中显示的应用程序引用。 szIdentifier 字段是用于向添加/删除程序注册应用程序的令牌。
FUSION_REFCOUNT_FILEPATH_GUID - 程序集由文件系统中的文件表示的应用程序引用。 szIdentifier 字段是该文件的路径。
FUSION_REFCOUNT_OPAQUE_STRING_GUID - 程序集由仅由不透明字符串表示的应用程序引用。 szIdentifier 是这个不透明的字符串。当您删除不透明引用时,GAC 不会执行存在性检查。

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:

KB317540: DOC: Global Assembly Cache (GAC) APIs Are Not Documented in the .NET Framework Software Development Kit (SDK) Documentation

var IAssemblyCache assemblyCache;
CreateAssemblyCache(ref assemblyCache, 0);


String manifestPath = "D:\Program Files\Contoso\Frobber\Grob.dll";

FUSION_INSTALL_REFERENCE refData;
refData.cbSize = SizeOf(refData); //The size of the structure in bytes
refData.dwFlags = 0; //Reserved, must be zero
refData.guidScheme = FUSION_REFCOUNT_FILEPATH_GUID; //The assembly is referenced by an application that is represented by a file in the file system. The szIdentifier field is the path to this file.
refData.szIdentifier = "D:\Program Files\Contoso\Frobber\SuperGrob.exe"; //A unique string that identifies the application that installed the assembly
refData.szNonCannonicalData = "Super cool grobber 9000"; //A string that is only understood by the entity that adds the reference. The GAC only stores this string

//Add a new assembly to the GAC. 
//The assembly must be persisted in the file system and is copied to the GAC.
assemblyCache.InstallAssembly(
      IASSEMBLYCACHE_INSTALL_FLAG_FORCE_REFRESH, //The files of an existing assembly are overwritten regardless of their version number
      manifestPath, //A string pointing to the dynamic-linked library (DLL) that contains the assembly manifest. Other assembly files must reside in the same directory as the DLL that contains the assembly manifest.
      refData);

More documentation before the KB article is deleted:

The fields of the structure are defined as follows:

  • cbSize - The size of the structure in bytes.
  • dwFlags - Reserved, must be zero.
  • guidScheme - The entity that adds the reference.
  • szIdentifier - A unique string that identifies the application that installed the assembly.
  • szNonCannonicalData - A string that is only understood by the entity that adds the reference. The GAC only stores this string.

Possible values for the guidScheme field can be one of the following:

FUSION_REFCOUNT_MSI_GUID - The assembly is referenced by an application that has been installed by using Windows Installer. The szIdentifier field is set to MSI, and szNonCannonicalData is set to Windows Installer. This scheme must only be used by Windows Installer itself.
FUSION_REFCOUNT_UNINSTALL_SUBKEY_GUID - The assembly is referenced by an application that appears in Add/Remove Programs. The szIdentifier field is the token that is used to register the application with Add/Remove programs.
FUSION_REFCOUNT_FILEPATH_GUID - The assembly is referenced by an application that is represented by a file in the file system. The szIdentifier field is the path to this file.
FUSION_REFCOUNT_OPAQUE_STRING_GUID - The assembly is referenced by an application that is only represented by an opaque string. The szIdentifier is this opaque string. The GAC does not perform existence checking for opaque references when you remove this.

抽个烟儿 2024-12-17 09:24:50

如果您安装了必要的.net框架。前任 ; .Net 4.0.Net 3.5,那么您只需将 Gacutil.exe 从任何计算机复制到新计算机即可。

1) 在新服务器中以管理员身份打开CMD。
2) 遍历到复制 Gacutil.exe 的文件夹。例如 - C:\program files。(就我而言)。
3) 在cmd提示符中输入以下内容并安装。

C:\Program Files\gacutil.exe /I dllname

if you have neccessary .net framework installed. Ex ; .Net 4.0 or .Net 3.5, then you can just copy Gacutil.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.

C:\Program Files\gacutil.exe /I dllname

那小子欠揍 2024-12-17 09:24:50

安装程序和 gacutil 的其他替代品是 GUI 工具,例如 Gac ManagerGACAdmin。或者,如果您喜欢 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.

只为一人 2024-12-17 09:24:50

请记住,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.

丑疤怪 2024-12-17 09:24:50

您还可以使用命令提示符将文件复制到 GAC。我使用以下批处理脚本复制 DLL 并重新启动 IIS。

copy /b/v/y "PathToAssembly\MyAssembly.dll" "C:\Windows\assembly\" 
iisreset /noforce
pause

无需使用或安装 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.

copy /b/v/y "PathToAssembly\MyAssembly.dll" "C:\Windows\assembly\" 
iisreset /noforce
pause

Saves the need to use or install gacutil

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