VS2022中Rust项目调试仍显示旧目录名,无法修改如何解决?
Visual Studio 2022 Rust项目调试名称不更新问题解决
项目信息
界面截图

Cargo.toml
[workspace] [package] name = "my_rust_workspace" version = "4.0.0-dev" edition = "2021" description = "Provides the package" license = "Apache-2.0" [dependencies] [[bin]] name = "main_executable" path = "./main.rs"
main.rs
fn main() { let c1 = 5; let c2 = 10; let _c3 = c1 + c2; let _c4 = 200; }
tasks.json(注:原文件名拼写错误,应为tasks.json)
{ "version": "2.0.0", "tasks": [ { "label": "cargo build", "dependsOn": [ "cargo build example" ] }, { "label": "cargo build release", "dependsOn": [ "cargo build example release" ] }, { "label": "cargo build example", "type": "cargo", "command": "build", "args": [], "problemMatcher": [ "$rustc" ], "options": { "cwd": "${workspaceFolder}" } }, { "label": "cargo build example release", "type": "cargo", "command": "build", "args": [ "--release" ], "problemMatcher": [ "$rustc" ], "options": { "cwd": "${workspaceFolder}" } }, { "type": "cargo", "command": "build", "problemMatcher": [ "$rustc" ], "group": "build", "label": "rust: cargo build" }, { "taskLabel": "task-Rust - vs2022 debug", "appliesTo": "/", "type": "launch" } ] }
launch.vs.json
{ "version": "0.2.1", "defaults": {}, "configurations": [ { "type": "native", "name": "C:\\git\\Rust - vs2022 debug", "project": "", "projectTarget": "" } ] }
问题
已将项目目录重命名为Rust - vs2022 debug,且右键cargo.toml设为启动项,但调试界面仍显示旧目录名称,找不到旧名称的存储位置进行修改。
解决方法
清理VS缓存
- 关闭Visual Studio 2022
- 删除以下路径的缓存文件:
%USERPROFILE%\AppData\Local\Microsoft\VisualStudio\17.0_*\ComponentModelCache%USERPROFILE%\AppData\Local\Temp\VisualStudioProjectSystem
- 重新打开项目
修改
.vs目录配置- 显示项目根目录的隐藏
.vs文件夹 - 进入
.vs\[旧项目名称]\v17路径,替换所有配置文件中的旧目录名称为新名称 - 也可直接删除
.vs下的旧项目名称文件夹,重启VS后会自动生成新配置
- 显示项目根目录的隐藏
重新生成启动配置
- 右键
Cargo.toml再次选择“设置为启动项目” - 启动调试,VS会自动生成适配新目录的配置文件
- 右键
可选:调整Cargo包名
- 如果希望调试界面显示的名称和包名一致,可以修改
Cargo.toml中package.name字段为Rust - vs2022 debug(不影响功能,仅修改Cargo识别的包名)
- 如果希望调试界面显示的名称和包名一致,可以修改
内容的提问来源于stack exchange,提问作者user366312
相关产品推荐
相关产品推荐

