Sometimes what you would think should work flawless, it turns out it doesn’t.
You are compiling in visual studio and you get this error:
Unable to remove directory "bin\Release\app.publish\"
Unable to remove directory "bin\Debug\app.publish\"
It doesn’t matter the project type; WPF, Winforms, ASP.NET, MVC, etc.
You probably have your solution files in a OneDrive folder with OneDrive client on.
It seems like OneDrive locks files for syncing or messes up with the files timestamps or attributes. Therefore Visual Studio is unable to remove the folder or files.
Just unload your OneDrive client, and wait a couple of seconds.
Your solution should now recompile again without problems.
You can turn OneDrive back on when you finish and let it resync.
Alternatively, you can go to OneDrive SettingsAccount/Choose folders, navigate to your project folder and unmark the “bin” folder. Also, you can just move your solution out of OneDrive.