c# - 文件被 Visual Studio 2019 锁定

标签 c# visual-studio visual-studio-2019 locked-files

我在 Visual Studio 中遇到一个奇怪的问题:

如果在调试过程中抛出未处理的异常,我将无法构建我的 C# 应用程序:

Unable to copy file "C:\Projects\A\bin\A.dll" to "..\..\bin\A.dll". 
  The process cannot access the file '..\..\bin\A.dll' because it is being used 
  by another process.

Could not copy "C:\Projects\A\bin\A.dll" to "..\..\bin\A.dll". 
  Exceeded retry count of 10. Failed. 
  The file is locked by: "Microsoft Visual Studio 2019 (14904)"

有没有永久的解决方案来解决这个奇怪的错误? (目前我唯一的解决方法是重新启动 Visual Studio)

我尝试过但不适合我的方法:

  • VS 菜单 -> 工具 -> 选项 -> 项目和解决方案 -> 生成并运行 -> 并将“设置最大并行生成数”设置为 1。
  • 停止防病毒软件
  • 启用应用程序体验服务(Windows 10 中未提供)
  • 取消勾选 VS 菜单 -> 工具 -> 选项 -> 项目和解决方案 -> 常规 -> 允许并行项目初始化
  • 取消勾选“调试”->“选项”->“调试”->“常规”->“当一个进程中断时中断所有进程”

在我的所有项目中插入预构建事件脚本也是不切实际的!链接:https://blog.ndepend.com/visual-studio-script-saves-time-pain/

有人能解决这个问题吗?

最佳答案

对我有用的方法 - 关闭解决方案,删除 bin 和 obj 文件夹,重新打开并构建。

关于c# - 文件被 Visual Studio 2019 锁定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56866981/

相关文章:

c# - 静态类以什么方式隐式抽象?

c# - 无法从均受 Azure AD B2C 保护的 MVC Web 应用程序访问 WebApi

azure - 使用 Powershell 7 在 Visual Studio 中验证/部署 ARM 模板

c# - 无法使用 XDocument 查询 XML 文档并获得所需的结果

c++ - 带有 Visual Studio 和 Unicode 源代码的 WxWidgets

c# - 为什么 Visual Studio 在 Razor (.cshtml/.razor) 中突出显示双花括号?

visual-studio - 如何阻止 Visual Studio 创建 pdb 调试文件夹?

c++ - 如何在cpp20实验中导入C断言

visual-studio - Visual Studio 2019 中的无效绑定(bind)

c# - 双重乘法给出 NaN