Resolving Access Denied Error In Roslyn Compiler

Facing a strange issue from Roslyn Compiler

When I built the solution, I faced a strange issue in error list which did not let me build the solution. Here is the error,
 
Unable to copy file "\visual studio 2017\Projects\..\packages\Microsoft.Net.Compilers.2.1.0\tools\System.IO.FileSystem.dll" to "bin\roslyn\System.IO.FileSystem.dll". Access to the path 'bin\roslyn\System.IO.FileSystem.dll' is denied
 
I started facing this problem recently in ASP.NET MVC. The first time I build the solution, it was working. But just after modifying the code, it started giving an error on rebuild. 
 
I cleaned the solution and built it again, and again, it works for the first time.

Then, I googled the problem and found that we can delete the files in bin/roslyn manually and build it again. Unfortunately, it worked for the first time only, like in previous efforts. 

Then, I found the solution which says that deleting this web.config part can solve the issue.
  1. <compilers>  
  2.     <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />  
  3.     <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />   
  4. </compilers>  
However, this solution may cause problems with new C# 6 features. Finally, I searched for another solution and come up with one that worked perfectly fine for me.
 
Open the Task Manager and end all the instances of VBCSCompiler.exe.
Even we don't need to close the VS. Just build and Rebuild again.
Ebook Download
View all
Learn
View all