41

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?

1

4 Answers 4

26

Your bestbet is to use a powershell script that wraps Publish.GacInstall, such as this one🕗

1
  • +1: WOW! This particular answers should be accepted, because it gives direct answer to the upper question. Force is string with you. Commented Jul 5, 2012 at 9:34
25

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

1
  • GacInstall seems to require an absolute path to your dll. Commented Nov 14, 2018 at 16:23
18

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.

Source

1
  • 2
    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
    Commented Feb 9, 2023 at 0:55
1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.