在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

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

调试器设置为


当前回答

问题是调试器/构建器创建的可执行文件或库被反病毒程序识别为威胁,因此在可以执行之前立即删除。

最好你应该调整你的反病毒软件,不分析你的项目文件夹。


按照从好到坏的顺序,有以下几种方法:

将项目文件夹从防病毒程序中排除 不包括pdb文件(不是100%保证修复) 关闭实时保护(不推荐)

其他回答

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

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

异常

在某些情况下,在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”

你很好!

@Gerard的答案是正确的。

当clean+build不能为我解决这个问题时,我通过以下方法取得了成功:

Closing Visual Studio
Deleting the bin and obj folders, and
Reopening Visual Studio.

但我需要在主机上做一些额外的工作:

> Add-Migration Initial
> Update-Database

然后我开始调试,它起作用了。

我正在研究一个微服务项目解决方案,我需要同时运行两个项目,冲突发生在lunchsettings.json applicationurl: {portNo}部分用于两个正在运行的项目是相同的端口

lunchsettings。第一个项目的Json

...
"Project#1": {
  ...
  "applicationUrl": "http://localhost:5001",
  ...
}

lunchsettings。第二个项目的Json

...
"Project#2": {
  ...
  "applicationUrl": "http://localhost:5001",
  ...
}

来修复它

lunchsettings。第一个项目的Json

...
"Project#1": {
  ...
  "applicationUrl": "http://localhost:5001",
  ...
}

lunchsettings。Json for secondproject

...
"Project#2": {
  ...
  "applicationUrl": "http://localhost:5002",
  ...
}

我意识到这只是为这个问题增加了一个已经非常多的答案,但我认为值得一提的是,尽管不完美,但@Stefano, @MichaelRibbons和@IvanFerrerVilla给出的答案的组合已经提供了一些不错的成功,因为他们各自都不太成功。