-->
Jan 09, 2011 Latest gacutil is part of Microsoft Windows SDK for Windows 7 and.NET Framework 4. Remember you can’t use previews version of gacutil (1.1 or 2.0/3.5) to register dll built in framework 4.0. If you don’t want to install whole SDK you need to copy.
The Global Assembly Cache tool allows you to view and manipulate the contents of the global assembly cache and download cache.
This tool is automatically installed with Visual Studio. To run the tool, use the Developer Command Prompt for Visual Studio (or the Visual Studio Command Prompt in Windows 7). For more information, see Command Prompts.
At the command prompt, type the following:
Syntax
Parameters
Argument | Description |
---|---|
assemblyName | The name of an assembly. You can supply either a partially specified assembly name such as myAssembly or a fully specified assembly name such as myAssembly, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0038abc9deabfle5 . |
assemblyPath | The name of a file that contains an assembly manifest. |
assemblyListFile | The path to an ANSI text file that lists assemblies to install or uninstall. To use a text file to install assemblies, specify the path to each assembly on a separate line in the file. The tool interprets relative paths, relative to the location of the assemblyListFile. To use a text file to uninstall assemblies, specify the fully qualified assembly name for each assembly on a separate line in the file. See the assemblyListFile contents examples later in this topic. |
Option | Description |
---|---|
/cdl | Deletes the contents of the download cache. |
/f | Specify this option with the /i or /il options to force an assembly to reinstall. If an assembly with the same name already exists in the global assembly cache, the tool overwrites it. |
/h[elp] | Displays command syntax and options for the tool. |
/iassemblyPath | Installs an assembly into the global assembly cache. |
/ifassemblyPath | Installs an assembly into the global assembly cache. If an assembly with the same name already exists in the global assembly cache, the tool overwrites it. Specifying this option is equivalent to specifying the /i and /f options together. |
/ilassemblyListFile | Installs one or more assemblies specified in assemblyListFile into the global assembly cache. |
/irassemblyPath scheme id description | Installs an assembly into the global assembly cache and adds a reference to count the assembly. You must specify the assemblyPath, scheme, id,and description parameters with this option. For a description of the valid values you can specify for these parameters, see the /r option. Specifying this option is equivalent to specifying the /i and /r options together. |
/l [assemblyName] | Lists the contents of the global assembly cache. If you specify the assemblyName parameter, the tool lists only the assemblies matching that name. |
/ldl | Lists the contents of the downloaded files cache. |
/lr [assemblyName] | Lists all assemblies and their corresponding reference counts. If you specify the assemblyName parameter, the tool lists only the assemblies matching that name and their corresponding reference counts. |
/nologo | Suppresses the Microsoft startup banner display. |
/r [assemblyName | assemblyPath] scheme id description | Specifies a traced reference to an assembly or assemblies to install or uninstall. Specify this option with the /i, /il, /u, or /ul options. To install an assembly, specify the assemblyPath, scheme, id,and description parameters with this option. To uninstall an assembly, specify the assemblyName, scheme, id,and description parameters. To remove a reference to an assembly, you must specify the same scheme, id, and description parameters that were specified with the /i and /r (or /ir) options when the assembly was installed. If you are uninstalling an assembly, the tool also removes the assembly from the global assembly cache if it is the last reference to remove and if Windows Installer has no outstanding references to the assembly. The scheme parameter specifies the type of installation scheme. You can specify one of the following values: - UNINSTALL_KEY: Specify this value if the installer adds the application to Add/Remove Programs in Microsoft Windows. Applications add themselves to Add/Remove Programs by adding a registry key to HKLMSoftwareMicrosoftWindowsCurrentVersion. - FILEPATH: Specify this value if the installer does not add the application to Add/Remove Programs. - OPAQUE: Specify this value if supplying a registry key or file path does not apply to your installation scenario. This value allows you to specify custom information for the id parameter. The value to specify for the id parameter depends on the value specified for the scheme parameter: - If you specify UNINSTALL_KEY for the scheme parameter, specify the name of the application set in the HKLMSoftwareMicrosoftWindowsCurrentVersion registry key. For example, if the registry key is HKLMSoftwareMicrosoftWindowsCurrentVersionMyApp, specify MyApp for the id parameter. - If you specify FILEPATH for the scheme parameter, specify the full path to the executable file that installs the assembly as the id parameter. - If you specify OPAQUE for the scheme parameter, you can supply any piece of data as the id parameter. The data you specify must be enclosed in quotation marks ('). The description parameter allows you to specify descriptive text about the application to install. This information is displayed when references are enumerated. |
/silent | Suppresses the display of all output. |
/uassemblyName | Uninstalls an assembly from the global assembly cache. |
/ufassemblyName | Forces a specified assembly to uninstall by removing all references to the assembly. Specifying this option is equivalent to specifying the /u and /f options together. Note: You cannot use this option to remove an assembly that was installed using Microsoft Windows Installer. If you attempt this operation, the tool displays an error message. |
/ulassemblyListFile | Uninstalls one or more assemblies specified in assemblyListFile from the global assembly cache. |
/u[ngen] assemblyName | Uninstalls a specified assembly from the global assembly cache. If the specified assembly has existing reference counts, the tool displays the reference counts and does not remove the assembly from the global assembly cache. Note: In the .NET Framework version 2.0, /ungen is not supported. Instead, use the uninstall command of the Ngen.exe (Native Image Generator). In the .NET Framework versions 1.0 and 1.1, specifying /ungen causes Gacutil.exe to remove the assembly from the native image cache. This cache stores the native images for assemblies that have been created using the Ngen.exe (Native Image Generator). |
/urassemblyName scheme id description | Uninstalls a reference to a specified assembly from the global assembly cache. To remove a reference to an assembly, you must specify the same scheme, id, and description parameters that were specified with the /i and /r (or /ir) options when the assembly was installed. For a description of the valid values you can specify for these parameters, see the /r option. Specifying this option is equivalent to specifying the /u and /r options together. |
/? | Displays command syntax and options for the tool. |
Remarks
Note
You must have administrator privileges to use Gacutil.exe.
Specifically, Gacutil.exe allows you to install assemblies into the cache, remove them from the cache, and list the contents of the cache.
Gacutil.exe provides options that support reference counting similar to the reference counting scheme supported by Windows Installer. You can use Gacutil.exe to install two applications that install the same assembly; the tool keeps track of the number of references to the assembly. As a result, the assembly will remain on the computer until both applications are uninstalled. If you are using Gacutil.exe for actual product installations, use the options that support reference counting. Use the /i and /r options together to install an assembly and add a reference to count it. Use the /u and /r options together to remove a reference count for an assembly. Be aware that using the /i and /u options alone does not support reference counting. These options are appropriate for use during product development but not for actual product installations.
Use the /il or /ul options to install or uninstall a list of assemblies stored in an ANSI text file. The contents of the text file must be formatted correctly. To use a text file to install assemblies, specify the path to each assembly on a separate line in the file. The following example demonstrates the contents of a file containing assemblies to install.
To use a text file to uninstall assemblies, specify the fully qualified assembly name for each assembly on a separate line in the file. The following example demonstrates the contents of a file containing assemblies to uninstall.
Note
Attempting to install an assembly with a filename longer than between 79 and 91 characters (excluding the file extension) can result in the following error:
Gacutil.exe Location Windows 10
This is because internally Gacutil.exe constructs a path of up to MAX_PATH characters that consists of the following elements:
- GAC Root - 34 chars (ie.
C:WindowsMicrosoft.NETassembly
) - Architecture - 7 or 9 chars (ie.
GAC_32
,GAC_64
,GAC_MSIL
) - AssemblyName - Up to 91 chars, depending on the size of the other elements (eg.
System.Xml.Linq
) - AssemblyInfo - 31 to 48 chars or more consisting of:
- Framework - 5 chars (eg.
v4.0_
) - AssemblyVersion - 8 to 24 chars (eg.
9.0.1000.0_
) - AssemblyLanguage - 1 to 8 chars (eg.
de_
,sr-Cyrl_
) - PublicKey - 17 chars (eg.
31bf3856ad364e35
)
- Framework - 5 chars (eg.
- DllFileName - Up to 91 + 4 chars (ie.
<AssemblyName>.dll
)
Examples
The following command installs the assembly
mydll.dll
into the global assembly cache.The following command removes the assembly
hello
from the global assembly cache as long as no reference counts exist for the assembly.Note that the previous command might remove more than one assembly from the assembly cache because the assembly name is not fully specified. For example, if both version 1.0.0.0 and 3.2.2.1 of
hello
are installed in the cache, the command gacutil /u hello
removes both of the assemblies.Use the following example to avoid removing more than one assembly. This command removes only the
hello
assembly that matches the fully specified version number, culture, and public key.Gacutil Path Windows 10
The following command installs the assemblies specified in the file
assemblyList.txt
into the global assembly cache.The following command removes the assemblies specified in the file
assemblyList.txt
from the global assembly cache.The following command installs
myDll.dll
into the global assembly cache and adds a reference to count it. The assembly myDll.dll
is used by the application MyApp
. The UNINSTALL_KEY MyApp
parameter specifies the registry key that adds MyApp
to Add/Remove Programs in Windows. The description parameter is specified as My Application Description
.The following command installs
myDll.dll
into the global assembly cache and adds a reference to count it. The scheme parameter, FILEPATH
, and the id parameter, c:applicationsmyAppmyApp.exe
, specify the path to the application that is installing myDll.dll.
The description parameter is specified as MyApp
.The following command installs
myDll.dll
into the global assembly cache and adds a reference to count it. The scheme parameter, OPAQUE
, allows you to customize the id and description parameters.The following command removes the reference to
myDll.dll
by the application myApp
. If this is the last reference to the assembly, it will also remove the assembly from the global assembly cache.The following command lists the contents of the global assembly cache.
See also
21 Oct 2015CPOL
This article outlines the steps for installing the Global Assembly Cache Tool on Windows Server 2008.
Problem
I have a customer using Windows Server 2008 for hosting its ASP.NET web applications. The operating environment on the server is kept very clean and lightweight, so only the bare necessities are installed. For example, there are no office productivity tools (like Office) or integrated development tools (like Visual Studio) installed in these environments. This is definitely a good practice; it keeps the potential attack surface small, and it helps to ensure that the server runs as fast as possible, without any potential for bogging down due to unnecessary programs or processes.
All of the web applications on this particular server rely on a Microsoft.NET assembly from a third-party software component vendor. The assembly DLL file is over 14 MB, which is relatively large, so we decided to move the DLL into the Global Assembly Cache (GAC) so it can be shared by all applications. Previously, a copy of the DLL was installed in the bin directory for every application that used it. This was wasteful of resources, and more difficult to maintain when the vendor released updates to the assembly.
You will recall the global assembly cache is machine-wide code cache that stores assemblies that are specifically intended for sharing by several applications on the computer. The Global Assembly Cache Tool (gacutil.exe) allows you to install assemblies into the cache, remove them from the cache, and list the contents of the cache. Using the tool to install an assembly into the cache is simple:
However, the
gacutil
executable did not exist anywhere on the server.According to Microsoft, gacutil.exe is considered to be a development tool. Because of this, it is contained in the .NET SDK and not in the .NET redistributable. Visual Studio comes with the SDK, so if you have Visual Studio installed, then this tool is installed with it. For example, on my development machine, the executable file is located here:
The application server has the .NET redistributable installed, but it does not have the .NET SDK installed, therefore this folder did not exist on the server, and there was no gacutil.exe.
Solution
One solution is to download and install the Microsoft Windows SDK for Windows 7 and .NET Framework 4. Version 7.1, published on May 19 of 2010, is available for free download here:
After downloading winsdk_web.exe, you can run the program with administrator permissions, and select the .NET Installation Options.
The installation takes a few minutes to run, and after it completes, the Global Assembly Cache Tool is ready to use.
I found this to be the simplest solution, although there are alternatives for adding assemblies to the GAC without installing the .NET SDK and without using gacutil.exe at all:
- If you have developed the application yourself, you can use the GacInstall method. For more information, refer to the class documentation for System.EnterpriseServices.Internal.Publish.
- Create a PowerShell script that wraps the
Publish.GacInstall
function. Here is one example. - Create a Microsoft Installer (MSI) package to deploy the assembly. Microsoft provides help documentation for this, and instructive tutorials are also available.