You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

更换Visual Studio后Flutter Windows应用无法运行求助

问题描述

卸载Visual Studio 2022预览版并安装正式版后,运行Flutter Windows项目时出现CMake错误,提示找不到预览版路径:

Launching lib\main.dart on Windows in debug mode...
Building Windows application...
CMake Error at CMakeLists.txt:3 (project):
  Generator

    Visual Studio 17 2022

  could not find specified instance of Visual Studio:

    X:/Program Files/Microsoft Visual Studio/2022/Preview


Exception: Unable to generate build files

flutter doctor显示所有Windows开发所需组件已正常安装:

[√] Flutter (Channel stable, 3.16.4, on Microsoft Windows [Version 10.0.19045.3803], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Enterprise 2022 17.8.4)
[√] Android Studio (version 2023.1)
[√] Connected device (3 available)
[√] Network resources
解决方案
  • 清理项目构建缓存
    执行命令清除旧构建配置:

    flutter clean
    
  • 删除Windows构建目录
    直接删除项目根目录下的build/windows文件夹,彻底清除残留的CMake缓存文件。

  • 重新初始化Windows桌面支持
    执行命令让Flutter重新检测Visual Studio环境:

    flutter config --enable-windows-desktop
    

    之后运行flutter doctor -v确认VS检测路径为正式版安装目录。

  • 手动指定CMake生成器(可选)
    如果上述步骤无效,运行项目时手动指定VS生成器:

    flutter run -d windows -DCMakeGenerator="Visual Studio 17 2022"
    

    或者检查项目windows/CMakeLists.txt的project行,确保没有硬编码旧的VS路径,默认配置下CMake会自动检测当前安装的VS版本。

  • 检查系统环境变量
    查看系统是否存在CMAKE_GENERATOR环境变量,若其值指向旧的预览版路径,删除该变量或修改为Visual Studio 17 2022。

内容的提问来源于stack exchange,提问作者Zahra

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 04:42:45