GAC DLL Link in Visual Studio

So, I looked around to try to find some posts about this, and there are many, but none of them relate to my specific question (which I could find).

I am trying to add some DLL to my project, but few of them:

C:\Windows\Microsoft.NET\Framework\v3.5\XXX.YYY.dll 

and I expect this to come from the GAC.

Please suggest me the best practice for referencing Dll in Visual Studio.

+8
dll visual-studio gac
source share
2 answers

This is not how it works. When you use Project + Add Reference, you always add a reference assembly. This is never a build from the GAC. The GAC is detailed runtime information that is always used to deliver assemblies when your program is running, never when it is built.

It is very important that it works this way, the contents of the GAC on your computer will not match the contents of the GAC on your user machine. Many DLL Hell countermeasures exist to ensure that matching your control assembly with GAC user content will take care of good diagnostics when the user computer is not configured correctly to run your program.

This is also the reason that you cannot directly browse GAC folders when navigating to c: \ windows \ assembly from Explorer. The shell extension handler hides the details so that you don't make a mistake, for example, by adding the GAC-ed assembly as a reference assembly. The same extension handler is not installed for .NET 4 builds, you can look at the c: \ windows \ microsoft.net \ assembly and see the GAC structure. Do not assume that now you can add links from there, link assembly is even more important in .NET 4, they are completely different from assemblies.

Thus, viewing the referenced assembly stored in C: \ Windows \ Microsoft.NET \ Framework \ v3.5 is completely normal; this is the home directory for special .NET 3.5 collections, such as System.Core.dll. For .NET 4 projects, reference assemblies are stored in c: \ program files \ reference assemblys, they must not be C: \ Windows \ Microsoft.NET \ Framework \ v4.0.30319. Check this answer to find out what unquenchable misfortune can be caused by not using the correct reference assemblies.

+23
source share

These assemblies are .NET Framework 3.5 assemblies. Build cache is in

 %SystemRoot%\assembly 

You can redistribute the .NET Framework 3.5 (scroll down the page) along with your project. Aso, if you use VS Setup projects, you can simply use the property page to link to it.

To reference these assemblies, you can easily right-click Links> Add Link and select an assembly from the .NET tab. For links to GAC assemblies, refer to this question .

+1
source share

All Articles