Visual Studio 2017 bin\roslyn files locked during build

Visual Studio-2017

Visual 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

Revert the Microsoft.CodeDom.Providers.DotNetCompilerPlatform package to V1.0.4

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

click to update enter image description here

Solution 7 - Visual Studio-2017

I have VS 2017 Enterprise and for me the issue was resolved by this:

  1. Downgraded Microsoft.Net.Compilers from 2.3.1 to 2.3.0
  2. 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:

  1. uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
  2. 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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJohn SView Question on Stackoverflow
Solution 1 - Visual Studio-2017Dean SwiatekView Answer on Stackoverflow
Solution 2 - Visual Studio-2017sansalkView Answer on Stackoverflow
Solution 3 - Visual Studio-2017Mircea MateiView Answer on Stackoverflow
Solution 4 - Visual Studio-2017andrew pateView Answer on Stackoverflow
Solution 5 - Visual Studio-2017threadsterView Answer on Stackoverflow
Solution 6 - Visual Studio-2017NewredView Answer on Stackoverflow
Solution 7 - Visual Studio-2017UsmanView Answer on Stackoverflow
Solution 8 - Visual Studio-2017TheDudeView Answer on Stackoverflow
Solution 9 - Visual Studio-2017JGilmartinView Answer on Stackoverflow
Solution 10 - Visual Studio-2017Imran Ahmad ShahidView Answer on Stackoverflow
Solution 11 - Visual Studio-2017moto_geekView Answer on Stackoverflow
Solution 12 - Visual Studio-2017hosseinView Answer on Stackoverflow
Solution 13 - Visual Studio-2017RuanView Answer on Stackoverflow
Solution 14 - Visual Studio-2017Muhammad Atif NadeemView Answer on Stackoverflow
Solution 15 - Visual Studio-2017Younis QadirView Answer on Stackoverflow
Solution 16 - Visual Studio-2017Rob HoffmannView Answer on Stackoverflow