What's the 'correct' way of registering/installing an Assembly to the GAC?

…衆ロ難τιáo~ 提交于 2019-11-27 08:54:54

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.

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.

Robert P

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).

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

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.

Robert P

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.

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).

Robert P

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).
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!