I need to register an assembly in the GAC using batch file. Is there a way to find the installation location of GacUtil.exe
or is there a way to register the assembly without GacUtil?
-
http://stackoverflow.com/a/2611435/17034 – Hans Passant Mar 17 '12 at 20:44
4 Answers
Your bestbet is to use a powershell script that wraps Publish.GacInstall, such as this one

- 246,734
- 253
- 869
- 1,219

- 12,701
- 7
- 36
- 42
-
+1: WOW! This particular answers should be accepted, because it gives direct answer to the upper question. **Force is string with you.** – Robert Koritnik Jul 05 '12 at 09:34
GacUtil is not installed with a framework install only with an SDK install - so you couldn't guarantee it would be on the box you're installing on.
This won't work within your batch file but if you have developed the application yourself you can use the GacInstall method described below:
http://msdn.microsoft.com/en-us/library/system.enterpriseservices.internal.publish.gacinstall.aspx
Alternatively I'd recommend producing an msi file to deploy the application. Tutorial here:
http://www.dreamincode.net/forums/topic/58021-deploying-a-c%23-application-visual-studio-setup-project/
It would be an inadvisable solution to include a copy of GacUtil.exe in your distribution because it comes under a different licence and you probably aren't licenced to redistribute it

- 3,781
- 5
- 34
- 56
You may install a dll into the GAC (global assembly cache) by doing the following
[Reflection.Assembly]::LoadWithPartialName("System.EnterpriseServices") | Out-Null
[System.EnterpriseServices.Internal.Publish] $publish = new-object System.EnterpriseServices.Internal.Publish
$publish.GacInstall(<<FullFilePathToTheDll>>)
This has to do very little with native PowerShell but rather with instantiating and using .NET libraries from PowerShell
Do a iisreset
.

- 3,547
- 3
- 29
- 50
-
This works great. The only "issue" is that when it fails, it fails silently. No return code. No exception. Apparently, something is written to the windows event log. For my purposes, I verified that the GACed dll was deposited in the expected file system location. Must be run "as administrator", was what was tripping me up. – MarkPflug Feb 09 '23 at 00:55
I used InnoSetup and created an installation including my assembly.
The important line is like below:
Source: "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"; DestDir: "{app}"; StrongAssemblyName: "WinSCPnet, Version=1.3.7.7333, Culture=neutral, PublicKeyToken=2271ec4a3c56d0bf, ProcessorArchitecture=MSIL"; Flags: ignoreversion gacinstall uninsnosharedfileprompt

- 1,852
- 26
- 29