views:

594

answers:

3

Hello,

Is there anyway to programmatically add a strong named assembly to the GAC using C# code ?

Thanks

A: 

just call gacutil command

gacutil /i mydll.dll
ArsenMkrt
Why the downvote?
TcKs
downvoter please leave comment
ArsenMkrt
Didn't downvote, but it appears that you haven't given enough information to answer the question.
JoshJordan
gacutil is a SDK command that may not be expected to be available on a user's machine
I can probably pack it as a resource .. extract it and run it .. correct ?
GX
Yea, you can bundle GACUTIL.EXE with your installation package
ArsenMkrt
see here http://channel9.msdn.com/forums/Coffeehouse/205281-Where-is-GACUTIL/
ArsenMkrt
I would not ship a version of gacutil that may or may not fit to the framework on the target machine.
+2  A: 

This Microsoft Support article, How to install an assembly into the Global Assembly Cache in Visual C#, should explain all you need to know.

This is typically a task performed by the installer, so I'm not sure why you'd want to do it from within a .NET program (unless I've misunderstood your question). However, you can simply use the System.Diagnostics.Process class to run all the necessary programs as an installer might.

Noldorin
Ok I will use the gacutil utility to add the assemblies to the Gac .. I thought there might be able to use an API to add an assembly to the GAC .. Thanks
GX
No problem. And yeah, I very much doubt there's a library/API to do this for you. The task is simple enough to use the command-line tools however.
Noldorin
To clarify, will an installer (produced by VS) automatically install my srongly named assemblies to the GAC?
Tom Wright
+1  A: 

The Global Assembly Cache is configured through a COM-like interface(http://support.microsoft.com/default.aspx?scid=kb;en-us;317540).

For all questions about the GAC, Jungfen Zhang's blog is the source of choice. http://blogs.msdn.com/junfeng/articles/229648.aspx
http://blogs.msdn.com/junfeng/articles/229649.aspx

For more information, search for "managed GAC API".

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

[Microsoft Installer] is the recommended and most common way to add assemblies to the global assembly cache. The installer provides reference counting of assemblies in the global assembly cache, plus other benefits.