Visual Studio 2017 bin\roslyn files locked during build

Solution 1:

Just open task manager and kill any instances of VBCSCompiler.exe. You don't even need to close Visual Studio.

Solution 2:

UPDATE the Microsoft.CodeDom.Providers.DotNetCompilerPlatform package to V1.0.7

  • Find Microsoft.CodeDom.Providers.DotNetCompilerPlatform from NuGet Uninstall Old version
    Install V1.0.7 or latest

Solution 3:

Instead of killing the process manually, you may use the following commands in a Pre-Build Event:

tasklist /FI "IMAGENAME eq VBCSCompiler.exe" 2>NUL | find /I /N "VBCSCompiler.exe">NUL
if "%ERRORLEVEL%"=="0" (taskkill /IM VBCSCompiler.exe /F) else (verify >NUL)