Best practice for developing .NET programs seems to be this: never reference dlls from GAC while developing.
However, How should I get the actual deployed product to reference the dlls in the GAC? For example, if my product is a very simple windows app, then how should I program my code so that the single deployed .exe file references System.Windows.Forms.dll from GAC?
I am new to .NET development, so I might be missing some very basics.
You add the references from the list in the
Add Referencesdialog. This adds entries to your.csprojthat look like the following:You don’t ship these dlls with your project. You could ship the redist setup of the .net framework, but that’s only a good idea if you ship physical copies of your program, not if you offer a download. Including them with your program is probably a copyright violation. And of course on Mono, future windows/.net versions etc a different
System.Windows.Formsassembly needs to be used, that wouldn’t work if you distributed your own copy of this file.These assemblies will get loaded from the GAC. But that’s fine since they are part of the .net framework after all. The compiled references will look similar to
mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. This way the framework will choose the correct version and will make sure that the references assemblies are from the correct creator.The guideline of not using the GAC refers to your own or third party assemblies. You ship those with your application and just have them in the same directory as your main program. Adding them to the GAC is only needed in a few specific scenarios.