We help IT Professionals succeed at work.

msbuild can't clean project with C# COM component dependant on other .NET library

I've got project A that depends on project C.  Project A is set up to be a COM object as well as a managed library.  Project B is a mixed C++ / Managed C++ library that bridges between our managed and unmanaged code.

Here's the error I get:

C:\Windows\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(854,9): error MSB3395: Cannot unregister assembly "F:\DOM\dev\DOM\R9_0\SRC\Execs\SvrCtl.dll". Could not load file or assembly 'M32UTIL, Version=, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

SvrCtl.dll is the COM one.  M32UTIL is the C++ library one.

The problem seems to be that M32Util gets cleaned first off, and then when msbuild goes to clean SvrCtl.dll then it causes a library loading error.
Watch Question

I got around this problem by cleaning the .NET assembly that was the COM component, SvrCtl, first, and then doing the clean using the .sln file.