在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

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

调试器设置为


当前回答

最快的方法是更改Build配置类型并再次返回到以前的配置。

其他回答

我在VS 2015中遇到了这个问题。我的环境的原因是使用StyleCop项目设置StyleCopAdditionalAddinPaths Include="…"来指定额外的StyleCop Addin路径。我使用的变通方法是从.csproj文件中删除这个项目设置,取而代之的是手动复制StyleCop AddIn中的StyleCop. csharp . rules .dll。不是一个优雅的解决方案,但我发现解决方案从来没有锁定dll之后,这样做。

必须在关闭后终止进程。 我用;

Process.GetCurrentProcess().Kill();

将此代码添加到您用于关闭的关闭事件或方法。

异常

在某些情况下,在Visual Studio当你(Build || Rebuild)在上面 运行IISExpress时,你会遇到这个异常:

无法复制文件"obj\Debug\YourProjectName.dll"到bin\YourProjectName.dll"。进程无法访问该文件 'bin\YourProjectName.dll',因为它正在被其他人使用 过程

解决方案

右键单击需要构建的web项目。 单击属性。 在左侧选择Build Events选项卡。 在Pre-build events命令行中粘贴这两行:

tasklist /fi “imagename eq iisexpress.exe” |find “:” > NUL 如果错误级别 1 任务杀死 /f /im “iisexpress.exe”

你很好!

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

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

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

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

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

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

如。

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

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

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