How to Register a .Net Dll File in the Gac

How to register dll in GAC with .Net MSI

If you have an VS Setup Project

After adding your outputs and files etc.

Right click on your msi project app root and choose view then File System

Here you will see where all your files are installing and also notice a Global Assembly Cache Folder. By dragging and dropping the dlls you want to be in the GAC into this folder, when you running your msi it will install all of your dlls into the GAC.

As an aside
Be careful when installing this onto your local machine, if you are trying to run a debug routine and have a reference to a version of a dll that exist in your GAC it will use this reference instead of the one in your solution.

A fix for this is to change the version number of the relevant project in your VS solution as soon as you have added the latest version to the GAC.

How to register DLL in the GAC?

Here are two methods.

  1. Using the utility gacutil -i

    gactutil -i c:\foldername\assemblyname.dll

  2. The second method is you can drag the .dll file from the bin folder of the assembly and drop it into the folder C:\%systemroot%\Assembly

Register DLL in GAC (CMD or PowerShell)

Remember to run PowerShell as administrator or this won't work.

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

You will likely need to restart whatever related service or program after this, for example:

if (Get-Service "YourService" -ErrorAction SilentlyContinue)
{
Stop-Service -Name 'YourService'
Start-Service -Name 'YourService'

}

Or just restart your computer.

How to install dll into GAC.

To answer your last question, yes, you must strong-name your assembly in order to install it into the GAC.

Something tells me that you don't really need to add your assembly to the GAC. Only in very few cases is there a benefit to doing this. Unless you know what these cases are, and know they apply to you, I'd suggest you forget about it.

COM .NET DLL not registering in the GAC (REGDB_E_CLASSNOTREG)

The reason you are getting the error REGDB_E_CLASSNOTREG is because your .net COM DLL is not registered. Any .net assembly needs to be registered for it to be exposed as a com class to the clients. We need to use regasm.exe to register the .net assembly.

Register custom C# assemblies in the GAC

You need to open the command prompt which comes with VS.

You need to use the gacutil tool

gacutil /i myown.dll

For more info:

http://msdn.microsoft.com/en-us/library/ex0ss12c%28v=vs.80%29.aspx

You can refer this page for doing so programmatically:

http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/7d3165cf-ca3b-43cc-8f77-a46dbf38f13d/

You can otherwise use Microsoft Windows Installer for deploying your application :

http://codefornothing.wordpress.com/2007/11/27/short-msi-tutorial/

And you can find the MSI here, if need be.

http://www.microsoft.com/en-in/download/details.aspx?id=25#overview



Related Topics



Leave a reply



Submit