I'm really going crazy over this problem with MSBuild. Let me give you some background information first…
We have a solution which produces a web service project. This web service depends on having a specific assembly in its bin-folder in order to run properly, but this assembly is not being refered to in any of the compiled code (it is a custom data provider that is only refered to in web.config and then dynamically loaded). The assembly is always found in (at least one) of the current assembly folders on all our machines, but the actual path can vary.
We build all our solutions using Team Foundation Server Build on a separate build box (actually a virtual server). TFSBuild, of course, uses MSBuild in order to build the actual solution. During the build process, we also run all unit tests that have been written against the webservice.
Now here comes the problem.. MSBuild, when figuring out which assemblies that should be copied to the website bin directory, doesn't understand that our custom data provider assembly must be included. This, of course, is not so strange since the assembly isn't referenced anywhere in the code. But when running the tests, the assembly must be in place, otherwise they all fail.
Unfortunately, I have still not found a reasonable solution to this problem. Here is a list of the things I've tried so far:
- Add a file reference to the web project. This creates a file called .refresh in the Bin directory of the solution. This file is then used to resolve the reference and add it. But, the file path is relative to the current solution, and since the folder setup is different on the build box than on my (and other developer's), this fails.
- Add a file reference to any other project in the solution (that is in its turn referenced by the web project). This actually works fine when building within Visual Studio, but the reference is ignored when building on the build box. This is probably because MSBuild is used in a different manner when building inside the IDE than it is when building from the command line.
- Overriding the AfterDropBuild target to manually copy the assembly. Works fine in order to get the final build drop to work, but since the testing is done prior to this (and in a completely different directory) the tests still fail
As I'm writing this, I realize that there probably is a target somewhere that can be overridden after the build but before the testing where I could copy the assembly. I'll probably try that tomorrow. Still.. Why is this so difficult??
Update – the simple solution
The painfully obvious solution was of course to edit the .refresh file so that it contains the complete UNC path to the assembly on the build box. Can't believe I didn't think of this before..