[c#] How do I register a .NET DLL file in the GAC?

I have made a .NET .DLL file, which I want to register in the GAC.

I have used this command in Windows Server 2003 Command Prompt:

C:\"Path of dll"\>gacutil /i dllname.dll
'gacutil' is not recognized as an internal or external command,
operable program or batch file.

It says the path is not correct.

Do I need to use this in a .NET cmd prompt? If it is that, I am not able to locate the .NET cmd prompt.

This question is related to c# gac dllregistration

The answer is


Try GACView if you have a fear of command prompts.

You have not set the PATH properly in DOS.You need to point the path to where the gacutil resides to use it in DOS.


As ando said, just drag and drop the assembly to the C:\windows\assembly folder. It works.


Just drag and drop the DLL file into folder C:\Windows\assembly using Windows Explorer.

Caveat:

In earlier versions of the .NET Framework, the Shfusion.dll Windows shell extension let you install assemblies by dragging them to File Explorer. Beginning with .NET Framework 4, Shfusion.dll is obsolete.

Source: How to: Install an assembly into the global assembly cache


From Wikipedia:

gacutil.exe is the .NET utility used to work with the GAC.

One can check the availability of a shared assembly in GAC by using the command:

gacutil.exe /l "assemblyName"

One can register a shared assembly in the GAC by using the command:

gacutil.exe /i "assemblyName"

Or by dropping an assembly file into the following location using the GUI:

%windir%\assembly\

Other options for this utility will be briefly described if you use the /? flag, that is:

gacutil.exe /?

In case on windows 7 gacutil.exe (to put assembly in GAC) and sn.exe(To ensure uniqueness of assembly) resides at C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin

Then go to the path of gacutil as shown below execute the below command after replacing path of your assembly

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin>gacutil /i "replace with path of your assembly to be put into GAC"


The above solutions look marvelous. However, to be simple, all you need I guess is to enter the assembly name along with its full path like:

gacutil -i C:\MyDlls\GacDeployedAssemblies\dllname.dll

Paying attention to C:\MyDlls\GacDeployedAssemblies


I tried just about everything in the comments and it didn't work. So I did gacutil /i "path to my dll" from Powershell and it worked.

Also remember the trick of pressing Shift when you right-click on a file in Windows Explorer to get the option of Copy path.


  • Run Developer Command Prompt For V2012 or any version installed in your system

  • gacutil /i pathofDll

  • Enter

Done!!!


You'll need:

  • Strong name your assembly (Visual Studio, Project Properties, Signing tab, Sign the assembly)
  • Alter your Build Events (Project Properties, Build Events tab, Post-build command line)
   cd C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin
   gacutil.exe /i "$(TargetPath)" /f /nologo
   gacutil /l "$(TargetName)" /nologo

Now, everytime you build your project, it'll be installed on GAC.


From the Publish tab go to application Files.

Then, click unnecessary files.

After that, do the exclude press ok.

Finally, build the project files and run the projects.


These responses don't tell you that gacutil resides in C:\WINDOWS\Microsoft.NET\Framework\v1.1* by the way.

I didn't have it in my v2.0 folder. But I tried dragging & dropping the DLL into the C:\WINDOWS\Assembly folder as was suggested here earlier and that was easier and does work, as long as it's a .NET library. I also tried a COM library and this failed with an error that it was expecting an assembly manifest. I know that wasn't the question here, but thought I'd mention that in case someone finds out they can't add it, that that might be why.

-Tom


You can do that using the gacutil tool. In its simplest form:

gacutil /i yourdll.dll

You find the Visual Studio Command Prompt in the start menu under Programs -> Visual Studio -> Visual Studio Tools.