File is locked by Visual Studio 2019

It's a little bit weird but the problem was caused by the Debug option Use Managed Compatibility Mode! So just untick Debug -> Options -> Use Managed Compatibility Mode and no more files locked errors by Visual Studio!

Remark: The downside of disabling this option is you will get annoying long time consuming evaluation errors by VS! (More information)


What worked for me - Close the Solution, Delete the bin and obj folder, re-open and build.