Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS2012 Test explorer locks native .dll, making rebuilds fail

Tags:

I am using Visual Studio 2012 for a solution with a C# and a C++/CLI .dll, with the C++/CLI dll referencing native .dlls such as boost. The C++ code is compiled as x64.

When I open VS, I can clean and build my project.

Using test explorer, I can run my tests.

As soon as I've used test explorer to run tests once, I cannot rebuild the project. It seems that VS2012 Test Explorer keeps a lock on my C++/CLI-dll, and there I get the following error:

LNK1104: cannot open file 'C:\Dev\LockExample\bin\Debug\cli.dll' 

As a result of this, whenever I have run the tests using Test Explorer, I need to restart VS2012 before I can continue developing. Obviously this is not a sustainable development process.

Testing and rebuilding works without problem with C#-only dlls - as far as I can tell the problem only occurs with DLLs that use native x64 code.

After some more testing, I found that the villain here is vstest.executionengine.exe. Using handle (from SysInternals), I see that vstest.executionengine.exe holds locks for the .dll and the .pdb of the cli-dll. It does not hold any locks for managed-only dlls.

How can I get Visual Studio Test Explorer to release the locks on the C++/Cli dlls after the test runs completed?

like image 744
Wilbert Avatar asked May 24 '13 09:05

Wilbert


2 Answers

In Visual Studio 2013 this problem can easily be fixed by unchecking the option "Keep Test Execution Engine Running" under "Test -> Test Settings" in the menu.

I found the answer in another post: vstest.executionengine.x86.exe not closing

like image 177
frodesto Avatar answered Oct 04 '22 10:10

frodesto


After some more searching, I found this post on connect.microsoft.com. The last hint in workarounds does solve the problem, although it's an ugly hack.

I can rebuild if I add the following as pre-build events to my C++/CLI dll:

taskkill /F /IM vstest.executionengine.exe /FI "MEMUSAGE gt 1" taskkill /F /IM vstest.executionengine.x86.exe /FI "MEMUSAGE gt 1" 

This will kill the vstest.executionengine.exe process, thereby freeing the lock on my .dll file.

like image 30
Wilbert Avatar answered Oct 04 '22 11:10

Wilbert