简体   繁体   中英

How to set the “Copy Local Dependencies” in C# projects [problem with CopyLocal]

I have an assembly called A.dll that has a project reference to an assembly called B.dll. The assembly referenced B.dll has a binary reference to C.dll.

A.dll --> B.dll --> C.dll

I've set at A.dll the "Copy Local" of B to true and I've set at B.dll the "Copy Local" to false of C.dll.

Anyway when I build A.dll I end with C.dll at the result folder. Why is not taken into account the "Copy Local" value of B.dll to C.dll?

Thanks

That's because msbuild was able to find c.dll. It doesn't know anything about the copy local setting of the B project. It simply looks at the .assembly directives in the metadata of b.dll and sees that c.dll is a dependency. And if it can find c.dll then it will copy it. If it cannot find it then nothing happens, no complaints either.

The odd part, and your solution, is that c.dll is present in the same directory as b.dll. How did it get there? Just stop it from getting copied there and it won't get copied to the A build directory either. It is otherwise quite murky how you'd expect this to ever run.

That's because CopyLocal copies the referenced assembly and its dependencies to the output folder, except if the referenced assembly or dependency resides in the GAC .

Since you set CopyLocal on the referenced B , both B and its dependency C will be copied to A 's output folder, even if you did not set CopyLocal on the referenced C in the B project.

Note that if you build B , C is not copied to B 's output folder.

If you want B to be copied to A 's output folder but don't want the same to happen to C , one solution would be to put C in the GAC.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM