I am developing an assembly which has to be installed in the GAC, and as part of a post-build step I ensure that the GAC gets updated after each build. If I create a (Visual Studio) unit test (in a seperate tests assembly) to call a new method on a class under test, then implement the method on the class under test (TDD style), then run the test (CTRL R, T) the assembly under test and the unit test project get built (and the assembly is updated in the GAC).
The test fails (throws a System.MissingMethodException for the new method). If I now debug the test the test passes and thereafter I can run the test and it will pass.
As part of my investigation I added an endless loop to the test and then ran it. I used Process Explorer to find the path of the dll that gets loaded during the test. I find that there is a handle to an assembly in C:\WINDOWS\assembly\temp\4XY349E7C5. Using the trick I found here to look in that directory I find an older version of my dll than is in the GAC, and if I use Reflector to examine the dll I find it does not contain the new method I added which explains the MissingMethodException.
So why does VSTestHost.exe load the dll in the temp directory, and is there some way for me to ensure the correct dll is used?