visual studio copy dll references to output folder

2019-01-15 06:29发布

问题:

I am trying to extend a certain application. I am using a DLL which comes bundled with that application to extend its functionality. I am using visual studio 2010 express edition. I added a reference to the dll library. In the reference properties the option "Copy local" is disabled.(greyed out) why is that? I want visual studio to copy the dll to my release folder. If this can't be done is there another way to bundle the dll?

回答1:

Your comment to Hans answer indicates this is a COM assembly and that you are using Visual Studio 2010.

This means the assembly reference was likely added with the "Embed Interop Types" setting set to true. This has the effect of linking the COM assembly into your binary removing the need to deploy it altogether. The following link has a more detailed explanation

  • http://msdn.microsoft.com/en-us/library/dd409610.aspx

If you do want to deploy it though then will need to do the following

  • Click on the reference in the references tab
  • Hit F4 to bring up the properties grid
  • Set "Embed Interop Types" to False (this will ungray Copy Local)
  • Set "Copy Local" to true


回答2:

It depends on what kind of DLL it is. If it is a COM server then Copy Local is off when you have a PIA registered for that COM server. If it is a regular .NET assembly then it will be off when it is registered in the GAC.

Fix the issue by, respectively, using regasm /u to unregister the PIA or gacutil /u to remove it from the GAC. Do note that you might not want to do this if this DLL requires that its installer is executed on the target machine. Which is likely. Talk to the component vendor or author to find out what you should do.