首页 > 解决方案 > dart pub 全局包在 Windows 10 上运行两次

问题描述

Dart 全局包安装

pub 全局激活

总是在我的 Windows 10 机器上运行两次


Dart SDK version: 2.13.4 (stable)

在此处输入图像描述

标签: dart

解决方案


我找到的解决方案是编辑 .bat 文件

C:\Users\$Username\AppData\Local\Pub\Cache\bin


原始bat文件

  @echo off
  rem This file was created by pub v2.13.4.
  rem Package: dart_clean
  rem Version: 0.1.3
  rem Executable: dart_clean
  rem Script: main
  if exist  "C:\Users\EBrain\AppData\Local\Pub\Cache\global_packages\dart_clean\bin\main.dart-2. 13.4.snapshot" (
  dart "C:\Users\EBrain\AppData\Local\Pub\Cache\global_packages\dart_clean\bin\main.dart-2.13.4.snapshot" %*
  rem The VM exits with code 253 if the snapshot version is out-of-date.
  rem If it is, we need to delete it and run "pub global" manually.
  if not errorlevel 253 (
    goto error
  )
  pub global run dart_clean:main %*
  ) else (
  pub global run dart_clean:main %*
  )
  goto eof
  :error
  exit /b %errorlevel%
  :eof

修改过的bat文件

@echo off
rem This file was created by pub v2.13.4.
rem Package: dart_clean
rem Version: 0.1.3
rem Executable: dart_clean
rem Script: main
pub global run dart_clean:main %*

goto eof
:error
exit /b %errorlevel%
:eof

但是每次更新包或激活新包时,我都必须回去编辑bat文件,这真的很不方便。

有任何合法的方法可以防止 pub 全局包运行两次。


推荐阅读