Visual Studio 2017 could not copy dll, because it's being used by MSBuild.exe process

753 views Asked by At

I have a solution with 2 projects included: a WPF Applicatin and a ClassLibrary (tried both Standard and Framework template). The WPFApp references the ClassLibrary.

The problem is: when I try to build the solution I get the following error:

Unable to copy file "obj\Debug\ClassLibrary.dll" to "bin\Debug\ClassLibrary.dll". The process cannot access the file 'bin\Debug\ClassLibrary.dll' because it is being used by another process.

If I end the MSBuild.exe process, everything works fine (until I change something on the ClassLibrary and try to build the solution)

I tried pre and post-build events with

taskkill /F /IM MSBuild.exe

But it doesn't work, just got some new errors. I guess it's due to MSBuild closing itsefl.

Do you have any idea of how to deal with that problem or at least what is the reason of such MSBuild behavior?

1

There are 1 answers

1
Radosław Panuszewski On BEST ANSWER

It seems that FodyWeaver is causing the issue.

Quote from the project page on GitHub:

Not Supported:

[...]

I think that Fody just messes up with the build process. Maybe it does something like a build task (as @Crowcoder suggested) and thus MSBuild locks the dll.

After switching back to packages.config problem disappeared.