0

I tried to find a way for intalling and uninstalling dlls from the GAC by C# code, but the only thing I find about it that's something with "Gacutil.exe", and it's very unclear how to use it.

There is a better way for install\ uninstall files from the GAC. Thanks

Erez
  • 87
  • 1
  • 6
  • What are you trying to do, a setup project? – Anil Jan 25 '16 at 12:31
  • Install some DLLs i make in my .net project to the GAC. – Erez Jan 25 '16 at 12:34
  • Why do you want to install in GAC, before answering please read http://stackoverflow.com/questions/2451123/when-should-i-deploy-my-assemblies-into-the-gac and http://stackoverflow.com/questions/498361/when-and-when-not-to-install-into-the-gac ? – Anil Jan 25 '16 at 12:35
  • I programming for sharePoint - i do it untill now manually and I KNOW i need it. just asked how to do it. – Erez Jan 25 '16 at 12:39
  • So you wanted to make a utility to execute a command like gacutil, what about a simple batch file? – Anil Jan 25 '16 at 12:40

2 Answers2

0

You can use PowerShell, for example. Or as you say use gacutill but Micsrosoft say:

Gacutil.exe is only for development purposes and should not be used to install production assemblies into the global assembly cache.

In my opinion best way is use installer to do this job. Libraries into the GAC should be added only during the installation and removed only during deinstallation.

Here is example how to setup installer. I think others installer should do this, too.

After research i found this: (as you want c# code ;-) )

To install an assembly into the GAC:

new System.EnterpriseServices.Internal.Publish().GacInstall("MyAssembly.dll");

To uninstall an assembly from the GAC:

new System.EnterpriseServices.Internal.Publish().GacRemove("MyAssembly.dll");
BWA
  • 5,672
  • 7
  • 34
  • 45
  • I asked "by C# code". thanks for answer, but please don`t write answers about things that i didn`s ask. – Erez Jan 25 '16 at 13:13
0

In a project file you can automatically GAC an assembly after a build by putting the following in the Post-Build event.

"C:\Program files\Microsoft Visual Studio 8\SDK\v2.0\Bin\GacUtil.exe" -i "$(TargetPath)"

In same way add uninstall cmd to prebuild.

Anil
  • 3,722
  • 2
  • 24
  • 49