什么是“正确的”? 向 GAC 注册/安装程序集的方式?

发布于 2024-07-07 12:06:16 字数 718 浏览 6 评论 0原文

向 GAC 注册程序集的方式似乎有很多不同,就像它们“有效”一样。 然而,“正确”的做法是什么?

回应 Lou Franco(和 gacutil):

我正在使用 Gacutil 进行开发,但在我看来这不是安装它的正确方法,因为 gacutil 不包含在 .NET 1.1 之后的基本 .NET 实用程序中 -它只是一个开发人员工具。

其他:Gacutil(如下面的回复所示)不可再分发,因此不应在您打算提供给非开发人员的任何应用程序中使用。 又名,客户。 请参阅 Aaron Stebner 的这篇博文(和评论)

回应使用 WIX:

WIX 可能很棒,但它在幕后是如何工作的呢? 哪些细节使得 WIX 安装程序集的方式成为正确的安装方式? 它是如何查找的? 它是系统/.NET 调用吗? 埋藏在 System32 中某处的 dll 中是否有需要进行的调用?

(编辑:看起来 WIX 在幕后使用 MSI。请参阅我在接受的答案中的评论。)

最终编辑:看起来将程序集安装到 GAC 的正确方法是使用 Windows 安装程序,而不是其他。 我要尝试一下Wix。 谢谢大家!

There seems to be lots of different ways to register assemblies with the GAC, as in, they 'work'. However, what's the "proper" way of doing it?

In response to Lou Franco (and gacutil):

I'm using Gacutil for development, but it seems to me to be not the proper way to install it, since gacutil isn't included in the basic .NET utilities past .NET 1.1 - it's only a developer tool.

Additional: Gacutil (as seen in responses below) is not redistributable, and therefore should not be used in any app that you intend to give to people who are not developers. AKA, customers. See This blog post (and comments) by Aaron Stebner.

In response to using WIX:

WIX might be great and all, but how does it work under the hood? What details makes the way WIX installs the assembly the right way to install it? How does it look it up? Is it a system/.NET call? Is there some call in a dll buried somewhere in System32 that needs to be made?

(Edit: it looks like WIX uses MSI under the hood. See my comments in the accepted answer.)

Final edit: It looks like the correct way to install an assembly to the GAC is using windows installer, and nothing else. I'm going to give Wix a try. Thanks all!

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

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

发布评论

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

评论(8

幻想少年梦 2024-07-14 12:06:16

对于 Wix,我会执行以下操作:

<DirectoryRef Id="MyDirectory" >
    <Component Id="MyComponent" Guid="PUT-GUID-HERE" DiskId="1">
        <File Id="MyAssembly" Name="MyAssembly.dll" Assembly=".net" KeyPath="yes" Source="MyAssembly.dll" />
    </Component>
</DirectoryRef>

当您在 WiX 中对文件使用属性 Assembly=".net" 时,它将在 MsiAssembly 和 MsiAssemblyName 表中为此组件创建条目,并将其标记为 GAC 组件。

With Wix I would do something like this:

<DirectoryRef Id="MyDirectory" >
    <Component Id="MyComponent" Guid="PUT-GUID-HERE" DiskId="1">
        <File Id="MyAssembly" Name="MyAssembly.dll" Assembly=".net" KeyPath="yes" Source="MyAssembly.dll" />
    </Component>
</DirectoryRef>

When you use the attribute Assembly=".net" for a file in WiX, it will create entries in the MsiAssembly and MsiAssemblyName table for this component and mark it as a GAC component.

爱的十字路口 2024-07-14 12:06:16

http://blogs.msdn.com/astebner/archive/2006/11/04/why-to-not-use-gacutil-exe-in-an-application-setup.aspx

看起来应该避免 gacutil; 它不是一个可重新分发的应用程序。 相反,安装它们的“正确”方法似乎是使用 MSI,其中一种方法是 WIX,如 CheGueVerra 或其他脚本发布的那样。

http://blogs.msdn.com/astebner/archive/2006/11/04/why-to-not-use-gacutil-exe-in-an-application-setup.aspx

It looks like the gacutil should be avoided; it's not a redistributable app. Instead, the 'proper' way of installing them seems to be using MSI, one way being WIX, as posted by CheGueVerra or another script.

小女人ら 2024-07-14 12:06:16

使用 System.EnterpriseServices.Internal.Publish 的 GacInstall 方法。

优点:看起来是一个内部工具。 可能做了所有正确的事情。

缺点:作为安装程序的一部分,您仍然需要制作并运行一个调用此功能的应用程序(除非您制作的安装程序是无论如何都会执行此操作的自定义应用程序)。

Use System.EnterpriseServices.Internal.Publish's GacInstall method.

Advantages: Seems to be an internal tool. Probably does all the right stuff.

Disadvantages: As part of an installer, you'd still need to make and run an app that calls this (unless the installer you make is a custom app that does it anyway).

开始看清了 2024-07-14 12:06:16

您的安装程序制造商没有办法将程序集安装到 GAC 中吗? 就你自己而言,我会说 GACUTIL:

http:// /msdn.microsoft.com/en-us/library/ex0ss12c(VS.80).aspx

Doesn't your installer maker have a way of installing an assembly into the GAC? On your own, I'd say GACUTIL:

http://msdn.microsoft.com/en-us/library/ex0ss12c(VS.80).aspx

离旧人 2024-07-14 12:06:16

如果您不想自己处理 gacutil 的东西,您可以随时在 Visual Studio 中创建一个安装项目。

但我自己会坚持使用 gacutil。

If you don't want to handle the gacutil stuff yourself, you can always create a setup project in visual studio.

But I'd stick with gacutil myself.

青春如此纠结 2024-07-14 12:06:16

使用 gacutil。

优点:似乎总是有效。
缺点:

  • 必须将额外的可执行文件与安装程序打包在一起。
  • 作为一个开发实用程序,似乎有额外的副作用(比如无论如何强制安装)。
  • 不应包含在提供给客户的任何可再分发文件中。

use gacutil.

Advantages: seems to always work.
Disadvantages:

  • must package an additional executable with your installer.
  • As a development utility, seems to have additional side effects (like forcing the install no matter what).
  • Should NOT be included in any redistributable given to customers.
感情旳空白 2024-07-14 12:06:16

最好的方法是使用gacutil -i Library.dll

gacutil 的唯一问题是它不在系统的默认路径中。 然而,对于给定的 .Net Framework 版本,它位于相对于 windows 目录的固定位置。 因此,您可以使用以下命令行从任何地方执行它:

%SystemRoot%\Microsoft.Net\Framework\v1.1.4322\gacutil -i

PS:仅将程序集复制到 c:\windows\Assembly 中是行不通的。 资源管理器仅显示文件夹的简化视图,其中实际上包含用于不同类型程序集的许多不同文件夹。 从安装程序中进行复制不会触发资源管理器通过拖放完成的所有操作。 (写在这里是因为我还没有足够的声誉来评论其他帖子)。

The best way is to use gacutil -i Library.dll.

The only problem with gacutil is that it is not in the default PATH of the system. It is however in a fixed location relative to the windows directory, for a given .Net Framework version. So you can use the following command line to execute it from anywhere:

%SystemRoot%\Microsoft.Net\Framework\v1.1.4322\gacutil -i

PS: just copying your assembly into c:\windows\assembly won't work. Explorer only shows a simplified view of the folder, which contains in fact lots of different folders for different kinds of assemblies. Doing a copy in it from an installer won't trigger all the operations done by explorer on a drag-and-drop. (written here because I don't have enough reputation yet to comment on other posts).

爱格式化 2024-07-14 12:06:16

直接复制到%WINDIR%\Assembly。

优点:简单直接。

缺点:据我所知,%WINDIR%\Assembly恰好位于现在的位置,并且它的位置可能会发生变化。 这将使其在 Windows 的未来版本中或该文件夹的行为发生变化时崩溃。 这可能不是正确的方法。

极端缺点:正如 madmath 所说:

仅将程序集复制到 c:\windows\Assembly 中是行不通的。 资源管理器仅显示文件夹的简化视图,其中实际上包含用于不同类型程序集的许多不同文件夹。 从安装程序中进行复制不会触发资源管理器通过拖放完成的所有操作。 (写在这里是因为我还没有足够的声誉来评论其他帖子)。

copy directly to %WINDIR%\Assembly.

Advantage: Straightforward.

Disadvantage: AFAIK, %WINDIR%\Assembly just happens to be where it is right now, and it's location is subject to change. This would make it break in future versions of windows or if that folder's behavior chaneges. This probably isn't the right way.

Extreme Disadvantage: As said by madmath:

just copying your assembly into c:\windows\assembly won't work. Explorer only shows a simplified view of the folder, which contains in fact lots of different folders for different kinds of assemblies. Doing a copy in it from an installer won't trigger all the operations done by explorer on a drag-and-drop. (written here because I don't have enough reputation yet to comment on other posts).

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