在VS2012 c#项目的构建过程中,我一直得到这个错误

Error   41  Could not copy "obj\Debug\WeinGartner.WeinCad.exe" to
 "bin\Debug\WeinGartner.WeinCad.exe". 
 Exceeded retry count of 10. Failed.    


Error   42  Unable to copy file "obj\Debug\WeinGartner.WeinCad.exe" to
"bin\Debug\WeinGartner.WeinCad.exe". The process cannot access the file
'bin\Debug\WeinGartner.WeinCad.exe' because it is being used by another 
process.    

现在我知道该终止进程了

Weingartner.WeinCad.vhost.exe

(有时)有用,但这让我很紧张。有办法阻止这一切发生吗?

调试器设置为


当前回答

在我的情况下(Windows 10, Visual Studio 2015):

任务管理器->用户-> EndTask=>vshost.exe

(它会立即重新启动,你可以重新构建)

其他回答

删除Bin文件夹中的Debug或Release文件夹下的所有.cache文件。

您可以通过脚本终止应用程序。

如果你的应用程序名为myapp.exe,在终端中运行下一个脚本:

taskkill /IM myapp.exe /F

参数为:

/IM   application name (imagename)

 /F                     Specifies to forcefully terminate the process(es).

第一个消息错误解决方案:

在我的例子中,问题在于路径长度。

解决方案是减少/更改问题文件路径。如果问题出在项目中的文件上,你应该减少/更改存储库路径。

C:\Users\userTest\folder1\folder2\folder3\...\folderX\myProject\...\file.exe

如。

C:\Users\userTest\folder1\myProject\...\file.exe

换句话说,默认情况下路径长度不能超过260个字符。

原线程答案 (https://stackoverflow.com/a/73686473/12678101)

用款。我通过编辑MSBuild.Community.Tasks.Targets文件并更改bin路径解决了这个问题:

<MSBuildDnnBinPath Condition="'$(MSBuildDnnBinPath)' == ''">$(MSBuildProjectDirectory)\bin</MSBuildDnnBinPath>

如果你使用Visual Studio Code (vsCode)遇到这个问题,或者你坚持使用终端命令,clean命令将删除构建文件,并通常修复描述的问题:

dotnet clean

然后,您可以返回运行:

dotnet build

or

dotnet run