Visual Studio - Reference of dlls are automaticall

2019-09-02 18:27发布

问题:

I am using Visual Studio 2010 with MCV4 (Installed separately).

Some dlls are linked to the orignal path, and some are copied to the project. I don't want them to be copied to the project.

i.e when building Web project (MCV4 -> Web API), I see several dlls, that automatically created: Antlr3.Runtime.dll - created on project folder (and path is not the original folder).

also: EntityFramework.dll, System.Web.Optimization.dll and some more,

where system.web is on C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Web.dll folder.

Why the above dlls are copied to the project folder, and how can I enforce that they would be on the original one?

Thanks :)

回答1:

If you rightclick each references assembly in your project there is a propery "Copy Local". For each reference you set Copy Local=true it will be copied into your output folder (\bin).

Unless the DLL is in the GAC (Global Assembly Cache), you will want to copy it locally as the application will not know where to load these DLLs from. By default when you add a reference, Copy Local will be true when the DLL is not in the GAC.

If the application can not find the DLL's it needs it will fail when the DLL is needed.

A .Net application can only load DLLs from the GAC or from your application path and subdirectories unless you employ your own Assembly.Load() code to do this.