10

I have two Unmanaged C++ DLLs in a solution, called A and B, and A has a reference to B. I want to copy B.dll to the application directory for A. When I click "Copy Local" on the reference in A's "Framework and References" tab in its project properties, it looks like it is set to true, but clicking apply reverts the value back to false. Any idea whats up here?

Jason Fry
  • 1,204
  • 12
  • 24
  • Very unclear, you cannot add a reference to an unmanaged C++ DLL there. – Hans Passant Nov 27 '12 at 18:09
  • @HansPassant B is a project reference to A. – Jason Fry Nov 27 '12 at 18:27
  • That tells the linker to link the .lib file produced by the B project. Copy Local only makes sense for .NET assemblies. Copy the DLLs with an xcopy command in a post build event. – Hans Passant Nov 27 '12 at 18:30
  • @HansPassant: Out of interest, would you know any good references on how to xcopy dlls reliably? – André Nov 27 '12 at 19:41
  • 1
    Not until I have an idea why xcopy would be unreliable. Use the /d and /y options. – Hans Passant Nov 27 '12 at 19:51
  • @HansPassant My managed projects get copied correctly when they are project references, any idea why this doesn't/cannot work for unmanaged project references? After all, the output of the two are the same, a DLL. Regardless, please post your response as an answer and I will accept it. – Jason Fry Nov 27 '12 at 21:56
  • 2
    I answered to similar question here http://stackoverflow.com/a/13944692/13441 – sergtk Dec 20 '12 at 12:53
  • 4
    I experience the **same behavior** (Copy Local cannot be set, it always reverts to its original value) with managed projects... MSVS 2012. – dom_beau Jan 08 '13 at 20:20

3 Answers3

1

I know it's been a while but I just ran into this issue and found this connect page:

https://connect.microsoft.com/VisualStudio/feedback/details/766064/visual-studio-2012-copy-local-cannot-be-set-via-the-property-pages

Seems like it's a known issue. You can work around it by editing the project file.

1

@HoopSomuah Even if you work around the connect bug and got the Copy Local setting to stick, Visual Studio still won't copy dependent libs or dlls into the target folder for A, no matter what flags you set on the reference to B in project A.

Unmanaged reference handling in Visual Studio 2015 is still screwed up and I'm sure 2017 is equally as bad.

@JasonFry As @HansPassant pointed out, you'll need to add a post-build event to project A to copy B.dll into the same folder as A.dll.

Visual Studio doesn't provide any easy way to obtain the path to B.dll from project A, so we can make project B write that path to a text file, and then have project A read the path from that text file and copy B.dll into the same folder as A.dll.

open the project properties for B and add this as a post-build event:

echo $(TargetPath)>$(SolutionDir)References.txt

in the project properties for A, add as as a post-build event:

for /f %%f in ($(SolutionDir)References.txt) do xcopy /y %%f $(TargetDir)

If you had a 3rd project C.dll that needs to be copied into A's output folder too, add a similar post-build event to the project properties for C (note >> instead of > so it appends to the text file instead of overwriting it):

echo $(TargetPath)>>$(SolutionDir)References.txt
0

I had this issue a while back. Basically, it is true, so it copies the file, and then sets itself to false to keep itself from recopying it.