Why MSBuild DOES copy dlls with copy local set to false?

1.3k Views Asked by At

That's the structure of our solution:

Solution.sln
  WebApp.csproj
    references ClassLibrary
  ClassLibrary.csproj
    references System.Net.Http.Formatting.dll with Copy local = false

When I build the Solution with source code of both WebApp and ClassLibrary, copy local works as expected and System.Net.Http.Formatting.dll is not copied to the WebApp/bin directory.

However, when we distribute our project to the end clients, we give them only the WebApp source code which reference compiled class libraries (.dll). In that case the Solution looks like this:

Solution.sln
  WebApp.csproj
    references ClassLibrary.dll which uses System.Net.Http.Formatting.dll

When this partially compiled Solution is compiled, the System.Net.Http.Formatting.dll is copied to the WebApp/bin folder which is causing us some troubles.

I've examined the detailed build output and dll is copied by the Copy task and the source location for this dll is

C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\System.Net.Http.Formatting.dll

There are some other mentions of the System.Net.Http.Formatting.dll assembly which I don't quite understand.

How to ensure that System.Net.Http.Formatting.dll isn't copied to the bin folder?

Thanks!

1

There are 1 best solutions below

3
On

It looks like the copylocal notation is in a project file that's not being read by the customer, so how would it know? You could add the references directly to the project file they do have, rather than letting them be discovered through transitive dependencies. Then you can mark them as no-copy-local. I think adding them as refs to WebApp.csproj should do the trick completely within the GUI. Start with that, and then fiddle with the XML if it's not quite good.