使用 VS 代码后货物构建中断

Cargo build broke after using VS code

一段时间以来,我一直在使用 Pycharm Professional 编辑我的 Rust 程序。但是,我很好奇并尝试了 VS Code。起初我的项目正在编译和 运行ning。然而,它突然开始在 cargo buildcargo 运行 上抛出一个非常疯狂的错误(而 cargo check 很好),即使在 VS Code 之外的 cmd 中也是如此:

error: linking with `link.exe` failed: exit code: 1104
= note: "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.30.30705\bin\HostX64\x64\link.exe" "/NOLOGO" "C:\rust\book\target\debug\deps\book.1apvyby1qhuehv3.rcgu.o" "C:\rust\book\target\debug\deps\book.1cw7xmk0cjjg5uln.rcgu.o" "C:\rust\book\target\debug\deps\book.1e8ho0j4rykowhcr.rcgu.o" "C:\rust\book\target\debug\deps\book.1g2fbveo2gp7bxds.rcgu.o"
..............
..............
= note: LINK : fatal error LNK1104: cannot open file 'C:\rust\book\target\debug\deps\book.exe'

book 是我的项目的名称。 我在 Windows 10,系统类型:基于 x64 的 PC。 VS 代码版本 1.63.2

不得不删除目录,并重新下载整个项目(使用 Git)。

有时 VSCode 文件监视程序会监视 target/ 中的文件,这不太好。 所以打开设置,搜索排除,并在所有“list-like”配置中添加 **/target/**,执行 cargo clean 并重新启动 VSCode。这应该可以解决这个问题和未来的问题