Jason Fry
Jason Fry

Reputation: 1234

Visual studio Copy Local on reference doesnt work

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?

Upvotes: 10

Views: 4450

Answers (3)

Ger O'Donnell
Ger O'Donnell

Reputation: 91

@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

Upvotes: 2

Hoop Somuah
Hoop Somuah

Reputation: 56

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.

Upvotes: 1

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.

Upvotes: 0

Related Questions