90

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.

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
Vineet
  • 5,029
  • 10
  • 29
  • 34

13 Answers13

109

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Fredrik Mörk
  • 155,851
  • 29
  • 291
  • 343
  • 10
    If you do not have Visual Studio, you can access gacutil.exe in C:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\ At least that is where it exists on a Win2012R2 server. – sonyisda1 Jun 10 '16 at 18:09
  • I have functions which requires elevation, so placing that dll in assembly will it have privileges? Will a non-administrator user able to run those functions in elevation? – Susarla Nikhilesh Jan 09 '19 at 14:03
  • My machine had it under C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools - it also required that I run the command via elevated command line. – neminem Sep 10 '19 at 17:46
  • latest versions of Visual Studio don't have "Command Prompt" separately in Start Menu. Its inbuilt in Visual Studio under "View > Terminal" – Gangula Jul 28 '22 at 07:19
36

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.

Rubens Farias
  • 57,174
  • 8
  • 131
  • 162
  • In Visual Studio 2017, you have to run VS as administrator or the gacutil fails for lack of permission. – Nathan Feb 20 '20 at 15:24
22

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

wp78de
  • 18,207
  • 7
  • 43
  • 71
Ando
  • 11,199
  • 2
  • 30
  • 46
  • 2
    You would need to be logged in with an admin account as "Run As" is not available for drag-n-drop. – Salman Siddiqui Jul 08 '14 at 15:17
  • 6
    This has no effect on my end - the library is not added, there's no error message. I am using an admin account. –  Jul 22 '14 at 23:03
  • 9
    "In earlier versions of the .NET Framework, the Shfusion.dll Windows shell extension enabled you to install assemblies by dragging them in File Explorer. Beginning with the .NET Framework 4, Shfusion.dll is obsolete." https://msdn.microsoft.com/en-us/library/dkkx7f79(v=vs.110).aspx – njplumridge Jan 04 '16 at 10:06
  • Emphasis on "drag and drop" - copy and paste doesn't work – Kind Contributor Jan 26 '16 at 02:12
15

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 /?
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
tbischel
  • 6,337
  • 11
  • 51
  • 73
  • GacUtil doesn't come with .NET. The shell drop-and-drop helper that used to allow dragging-and-dropping to register assemblies no longer works. – Ian Boyd Nov 19 '19 at 19:45
14

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

Tom
  • 169
  • 1
  • 3
5

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.

abmv
  • 7,042
  • 17
  • 62
  • 100
4
  • Run Developer Command Prompt For V2012 or any version installed in your system

  • gacutil /i pathofDll

  • Enter

Done!!!

  • mentioning 'Developer' command prompt, good! as gacutil is not available to build command prompt – Muds May 12 '16 at 09:31
2

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"

2

Also available using .NET Framework Assemblies in PowerShell.

[System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
$publish = New-Object System.EnterpriseServices.Internal.Publish     
$publish.GacInstall("C:\path_to_dll_file\file.dll")

Was searching some solution lately, tested this one before I found relevant info here.

peanek
  • 31
  • 4
1

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

Draken
  • 3,134
  • 13
  • 34
  • 54
vamsee
  • 31
  • 1
  • 9
1

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.

Siderite Zackwehdex
  • 6,293
  • 3
  • 30
  • 46
0

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.

dan1st
  • 12,568
  • 8
  • 34
  • 67
0

For adding your dll(for example csvhelper.dll) in GAC you can use the following command in cmd.

C:\test>"C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.7 Tools\gacutil.exe" -i csvhelper.dll

**Put your dll in a folder (for example in test folder)

**Pay attention which version of .Netframework you have(Here I used .net4.7)

p sharif
  • 1
  • 1