Loocid
Loocid

Reputation: 6441

MsBuild deletes dependency dlls when I build, then debug in Visual Studio

I have a project with the following simplified dependency structure (there are many projects in total).

MainWindow
 |- UserControl
   |- Library
     |- ExternalLib.dll

ExternalLib.dll is a Content resource with Copy Always.

When I build my project it correctly copies ExternalLib into my output folder. If I then click Debug it rebuilds my Library and UserControl projects and deletes my ExternalLib.dll

In the MSBuild build logs I see the following:

5>Task "Delete"
    ...
5>  Deleting file "/path/to/bin/ExternalLib.dll".
5>Done executing task "Delete".

Why would MsBuild be deleting a dependency of a project that the project I'm building in dependent on?

Upvotes: 3

Views: 883

Answers (1)

Loocid
Loocid

Reputation: 6441

I figured it out. Apparently if you have a project structure where A references B references C, if A doesn't need C the compiler is "smart enough" to delete C.

Because the reference to ExternalLib in my main application was through reflection, the compiler thought I didn't need the ExternalLib.

The problem can be solved in two ways:

  1. Have a dummy reference to C in A, eg just create an instance of a class that is found in C.
  2. Explicitly reference C in A.

Personally I went with the second option.

Upvotes: 1

Related Questions