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

Flutter运行Windows应用报Nuget.exe not found错误如何解决

问题表现

使用Flutter开发Windows桌面应用时,debug模式下启动流程未走完应用就直接退出,控制台输出报错如下:

Launching lib\main.dart on Windows in debug mode...
lib\main.dart:1
Nuget.exe not found, trying to download or use cached version.
Unable to load the service index for source https://dist.nuget.org/win-x86-commandline/latest/nuget.exe.
  The content at 'https://dist.nuget.org/win-x86-commandline/latest/nuget.exe' is not a valid JSON object.
  Unexpected character encountered while parsing value: M. Path '', line 0, position 0.
CMake Error at flutter/ephemeral/.plugin_symlinks/permission_handler_windows/windows/CMakeLists.txt:29 (message):
  Failed to install nuget package Microsoft.Windows.CppWinRT.2.0.210806.1
问题原因
  • Flutter构建Windows端产物时,自动拉取Nuget程序的逻辑出错,误将Nuget.exe的直接下载地址当成Nuget包源索引地址解析,返回的二进制可执行文件不符合JSON格式要求,解析直接失败
  • Nuget拉取失败后,permission_handler_windows插件依赖的Microsoft.Windows.CppWinRT.2.0.210806.1包无法完成安装,触发CMake构建错误,最终导致应用启动中断
解决步骤
  • 手动安装Nuget
    提前下载好nuget.exe文件,放到已加入系统环境变量PATH的目录下,新开终端窗口执行nuget help,能正常输出版本信息即安装完成
  • 校验Nuget源配置
    终端执行nuget sources list查看已配置的包源,确认默认官方源为Nuget官方v3索引地址;如果存在指向nuget.exe直链的错误源,先删除错误源再重新添加正确的官方包源
  • 清理缓存重新构建
    回到Flutter项目根目录,依次执行以下命令清理旧构建缓存、拉取依赖后重新启动:
    flutter clean
    flutter pub get
    flutter run -d windows
    
  • 手动补装缺失依赖(若上述步骤执行后仍报CppWinRT安装错误)
    进入项目下的windows子目录,执行nuget install Microsoft.Windows.CppWinRT -Version 2.0.210806.1手动安装对应版本的依赖包,安装完成后回到项目根目录重新执行构建启动命令即可

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.27 05:27:21