Visual Studio 2017 bin\roslyn files locked during build
Visual Studio-2017Visual Studio-2017 Problem Overview
I am running VS2017 version 26430.13 and every time I try to build a web project I get errors that access to the files in the bin\roslyn is denied. Over a period of about 5 minutes the files are unlocked and I can build but the 5 minute delay is unacceptable.
These are the files that stay locked:
- Microsoft.CodeAnalysis.CSharp.dll
- Microsoft.CodeAnalysis.dll
- Microsoft.CodeAnalysis.VisualBasic.dll
- Microsoft.DiaSymReader.Native.amd64.dll
- System.Collections.Immutable.dll
- System.Diagnostics.FileVersionInfo.dll
- System.IO.Compression.dll
- System.IO.FileSystem.dll
- System.IO.FileSystem.Primitives.dll
- System.Reflection.Metadata.dll
- System.Security.Cryptography.Algorithms.dl
- System.Security.Cryptography.Primitives.dl
- System.ValueTuple.dll
- VBCSCompiler.exe
Visual Studio-2017 Solutions
Solution 1 - Visual Studio-2017
Just open task manager and kill any instances of VBCSCompiler.exe. You don't even need to close Visual Studio.
Solution 2 - Visual Studio-2017
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 - Visual Studio-2017
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)
Solution 4 - Visual Studio-2017
A workaround is close VS, open task manager and kill any instances of VBCSCompiler.exe
(Thanks Tom John: https://developercommunity.visualstudio.com/content/problem/71302/binroslyn-files-locked-during-build.html)
Solution 5 - Visual Studio-2017
Microsoft.CodeDom.Providers.DotNetCompilerPlatform
package to V1.0.4
Revert the This advice came from a comment on the developer community problem report https://developercommunity.visualstudio.com/solutions/79954/view.html.
We were on v1.0.5 and experienced locked files frequently. After reverting the Microsoft.CodeDom.Providers.DotNetCompilerPlatform package to V1.0.4 we are no longer experiencing locked files.
Solution 6 - Visual Studio-2017
Project > Manage NuGet Packages... > Installed(tab) > in search input set this:
codedom
Solution 7 - Visual Studio-2017
I have VS 2017 Enterprise and for me the issue was resolved by this:
- Downgraded Microsoft.Net.Compilers from 2.3.1 to 2.3.0
- Downgraded Microsoft.CodeDom.Providers.DotNetCompilerPlatform from 1.0.5 to 1.0.4.
Solution 8 - Visual Studio-2017
Install Microsoft.CodeDom.Providers.DotNetCompilerPlatform.BinFix nuget It fixed the issue for me
Solution 9 - Visual Studio-2017
for me updating the nuget package...
> Microsoft.Net.Compilers
to the latest at the time of this post 2.7.0 fixed this for me. it was version 1.3.2
Solution 10 - Visual Studio-2017
For me I just open solution in file explorer and delete bin folders of all projects in it. now it's working fine.
Solution 11 - Visual Studio-2017
In VS2017 & VS2019, this can happen when IIS Express is still running. Open the tray next to the clock, hover over the IIS Express icon running, right-click on the icon, click "Exit", confirm prompt, close active running worker processes. This can also be true when trying to publish your web project as well.
Solution 12 - Visual Studio-2017
In my case I did these two steps:
- uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
- Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -Version 1.0.8
Solution 13 - Visual Studio-2017
Before you try anything drastic, restart your computer
Solution 14 - Visual Studio-2017
I was having the same issue in MVC 5. I just opened Nuget Package Manager, searched and updated the following:
Microsoft.CodeDom.Providers.DotNetCompilerPlatform
Solution 15 - Visual Studio-2017
Deleting this dll Microsoft.CodeDom.Providers.DotNetCompilerPlatform solved the issue for me
Solution 16 - Visual Studio-2017
Update the Microsoft.CodeDom.Providers.DotNetCompilerPlatform
package to V1.0.6