ChatGPT解决这个技术问题 Extra ChatGPT

Can not delete \bin\roslyn\VBCSCompiler.exe - Access is denied

I am facing a strange issue from roslyn compiler. Sometimes when I build the solution I face a strange issue in error list which does not let me build the solution. Here is the error:

Severity Code Description Project File Line Suppression State Error Unable to copy file "D:\Sealogical New Website\SealogicalWebsite\packages\Microsoft.Net.Compilers.1.0.0\tools\csc.exe" to "bin\roslyn\csc.exe". Access to the path 'bin\roslyn\csc.exe' is denied. SealogicalWebsite Severity Code Description Project File Line Suppression State Error Unable to copy file "D:\Sealogical New Website\SealogicalWebsite\packages\Microsoft.Net.Compilers.1.0.0\tools\VBCSCompiler.exe" to "bin\roslyn\VBCSCompiler.exe". Access to the path 'bin\roslyn\VBCSCompiler.exe' is denied. SealogicalWebsite

I try to clean the solution and rebuild it but does not work again. Tried to delete files manually but again shows an error pointing out I do not have right permissions to do this: Tried deleting from CMD but again shows the same error:

https://i.stack.imgur.com/XUcwF.png

The only way to delete roslyn generated files is by restarting the PC and when restarted I can delete them manually without a problem.

I am administrator in my PC so there is no problem with that I guess.

This problem seems to happen in Visual Studi0 2015 and Visual Studio 2017.

I dont like restarting the PC 4-5 times a day or more thats why I am asking here.

Some other details:

I am the one who created this project so theoretically it should not be a problem to do this action.

When the project first created I did run the Visual Studion in Administrator Mode as I am doing now.

I am using ASP.MVC 5 template in my project.

Files which do not get deleted are bin/roslyn/csc and bin/roslyn/VBCSCompiler.

I could find a solution to remove this part from web.config so it does not generate those files:

<compilers>
  <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" />
  <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=\&quot;Web\&quot; /optionInfer+" />
</compilers>

But this solution would cause problem with new c# 6 features so I can not remove this section.....

Furthermore I tried this command in CMD to see if there is a process locking this file but anyway it did not show me any process at all:

C:\WINDOWS\system32>tasklist /m D:\SealogicalNewWebsite\SealogicalWebsite\SealogicalWebsite\bin\roslyn\csc.exe
INFO: No tasks are running which match the specified criteria.

Does anybody knows a way how to handle this strange issue ?

There's probably a process running that has those files locked. Check the Task Manager to see if you can kill them. Also, unless you actually use VB, you can remove the language="vb... line
@CamiloTerevinto I culd notice a process using VBCSCompiler which I ended as a task but again does not work. I tried to end some other tasks I could think about using those files but no success
What happens if you re-download the NuGet package? (maybe update it?)
I am not sure for that because I have not tried to re-download them and even if I try it will take some time from next occurrence but I think I will try it as an alternative
Since a recent update of VS 2017, me and my co-workers are getting this issue, too. The pragmatic solution in my case was to simply kill the sitll running process "VBCSCompiler" manually via Task Manager.

A
Alex

Same problem here - solution for me was closing VS, open task manager and end all instances of VBCSCompiler.exe as mentionend here: https://developercommunity.visualstudio.com/content/problem/71302/binroslyn-files-locked-during-build.html


Sometimes it works and sometimes it doesnt but I will accept this as the best answer since I could not find any better answer than this one. Thanks :)
Per the link above on 09.27.2017 there is a fix slated for release in VS2017 V15.2.
VS 2019 latest version and still this answer solved my problem
t
tnapster

In the 'Manage NuGET Packages' window I downgraded Microsoft.Net.Compilers to 2.3.0 (from 2.3.1) and also downgraded Microsoft.CodeDom.Providers.DotNetCompilerPlatform to 1.0.4 (from 1.0.5) and the Roslyn directory/files were no longer marked as readonly and no longer locked by the exe.


Just run update-package for Microsoft.CodeDom.Providers.DotNetCompilerPlatform and Microsoft.Net.Compilers in nuget console.
S
Sanjeev Jyothikrishnan

Goto Taskmanager --> under process tab ---> find VBCSCompiler.exe and end this task. then try to delete the folder


E
EverLearning

I have killed the process in task manager and rebuilt the solution which gets me back on track, but I have found that frequently building the entire solution before debugging has stopped it all together. I am currently working on an n-tier application and I was encountering this numerous times a day and I haven't had the issue since I made sure to build the application after any changes and especially before debugging. Though, I don't get why this would work since the VS builds the solution before debugging but it has done the trick for me.


J
John

I accidentally found this in Task Manager:

Windows Explorer > (expand Windows Explorer) > Roslyn Right-click Roslyn and select End Task

Note: Even closing all Windows Explorer windows will not stop Roslyn. You must do this in Task Manager.


d
dawncode

I killed the visual studio instance from Task manager then it got deleted.