Skip to content

[Windows] support pubspec.yaml version/build number in windows projects #73652

Closed
getsentry/sentry-docs
#7155

Description

@narumi147

Steps to Reproduce

  1. flutter config --enable-windows-desktop
  2. create a new project and run flutter build windows, the built exe version should be 1.0.0.0
  3. change version in pubspec.yaml from 1.0.0+1 to any other version like 1.1.1+2
  4. pub get and build again, the version of exe is still 1.0.0.0
  5. flutter clean doesn't help

I have to change the default value of VERSION_AS_NUMBER and VERSION_AS_STRING in windows/runner/Runner.rc. However, these two value SHOULD be used only when FLUTTER_BUILD_NUMBER and FLUTTER_BUILD_NAME not defined, and they should be defined from version in pubspec.yaml when run pub get ?

#ifdef FLUTTER_BUILD_NUMBER
#define VERSION_AS_NUMBER FLUTTER_BUILD_NUMBER
#else
#define VERSION_AS_NUMBER 1,1,1,2
#endif

#ifdef FLUTTER_BUILD_NAME
#define VERSION_AS_STRING #FLUTTER_BUILD_NAME
#else
#define VERSION_AS_STRING "1.1.1.2"
#endif
flutter doctor -v
[✓] Flutter (Channel master, 1.26.0-2.0.pre.167, on Microsoft Windows [Version 10.0.19042.685], locale zh-CN)
    • Flutter version 1.26.0-2.0.pre.167 at D:\Projects\sdk\flutter
    • Framework revision d3a2259541 (9 days ago), 2020-12-31 15:14:03 -0500
    • Engine revision 82b4ae86d6
    • Dart version 2.12.0 (build 2.12.0-179.0.dev)
    • Pub download mirror https://pub.flutter-io.cn
    • Flutter download mirror https://storage.flutter-io.cn

[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at D:\Projects\sdk\Android\Sdk
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = D:\Projects\sdk\Android\Sdk
    • Java binary at: C:\Users\narumi\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-1\201.6953283\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[✗] Chrome - develop for the web (Cannot find Chrome executable at .\Google\Chrome\Application\chrome.exe)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Visual Studio - develop for Windows (Visual Studio Enterprise 2019 16.8.3)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise
    • Visual Studio Enterprise 2019 version 16.8.30804.86
    • Windows 10 SDK version 10.0.18362.0

[✓] Android Studio (version 4.1.0)
    • Android Studio at C:\Users\narumi\AppData\Local\JetBrains\Toolbox\apps\AndroidStudio\ch-1\201.6953283
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[✓] VS Code (version 1.52.1)
    • VS Code at C:\Users\narumi\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension can be installed from:
      🔨 https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (3 available)
    • sdk gphone x86 (mobile) • emulator-5554 • android-x86    • Android 11 (API 30) (emulator)
    • Windows (desktop)       • windows       • windows-x64    • Microsoft Windows [Version 10.0.19042.685]
    • Edge (web)              • edge          • web-javascript • Microsoft Edge 87.0.664.75

! Doctor found issues in 1 category.

Activity

  1. stuartmorgan-g commented on Jan 10, 2021

    @stuartmorgan-g
    Contributor

    However, these two value SHOULD be used only when FLUTTER_BUILD_NUMBER and FLUTTER_BUILD_NAME not defined, and they should be defined from version in pubspec.yaml when run pub get ?

    Setting those defines from pubspec.yaml has never actually been implemented; that code is there to future-proof projects so that it can be added later and existing projects will benefit automatically.

    I thought I filled an issue to track implementing that piece when landing the template, but I don't see it, so we can use this one.

  2. added
    a: buildBuilding flutter applications with the tool
    P3Issues that are less important to the Flutter project
    platform-windowsBuilding on or for Windows specifically
    toolAffects the "flutter" command-line tool. See also t: labels.
    on Jan 10, 2021
  3. changed the title [-][Windows] version/build number of built exe won't update when version changed in pubspec.yaml[/-] [+][Windows] support pubspec.yaml version/build number in windows projects[/+] on Feb 25, 2021
  4. fzyzcjy commented on Mar 5, 2022

    @fzyzcjy
  5. azimuthdeveloper commented on Apr 24, 2022

    @azimuthdeveloper

    It's a little hard to believe that Flutter for Windows went stable without this critical feature...

  6. Sunbreak commented on Apr 24, 2022

    @Sunbreak
    Contributor

    Try flutter_distributor according to fastforgedev/fastforge#65

  7. stuartmorgan-g commented on Apr 25, 2022

    @stuartmorgan-g
    Contributor

    It's a little hard to believe that Flutter for Windows went stable without this critical feature...

    It is a one-line change in Runner.rc to update the build number. Needing to change the version number in two places instead of one certainly isn't ideal, but "critical feature" substantially overstates the severity here.

  8. jmatth commented on Apr 25, 2022

    @jmatth
    Contributor

    Here are the Github Actions steps I'm using to replace the build number as part of the Windows build process:

          - name: Extract version from pubspec
            shell: bash
            run: |
              version="$(grep '^version:\s\+[[:digit:]]\+\.[[:digit:]]\+\.[[:digit:]]\+$' pubspec.yaml | head -n1 | awk '{print $2}')"
              if test -z "$version"; then
                echo 'ERROR: failed to get version from pubspec.yaml'
                exit 1
              fi
              echo "RELEASE_VERSION=$version" >> $GITHUB_ENV
              echo "RELEASE_VERSION_NUM=${version//./,}" >> $GITHUB_ENV
    
          # Several unrelated steps omitted
    
          - name: Fix app version (Windows)
            if: runner.os == 'windows'
            run: |
              (Get-Content .\windows\runner\Runner.rc) `
              -replace 'VERSION_AS_NUMBER 1,0,0', 'VERSION_AS_NUMBER ${{ env.RELEASE_VERSION_NUM }}' `
              -replace 'VERSION_AS_STRING "1.0.0"', 'VERSION_AS_STRING "${{ env.RELEASE_VERSION }}"' `
              | Out-File -Encoding UTF8 .\windows\runner\Runner.rc

    Note that it assumes the version number extracted from pubspec.yaml is in the form x.y.z. You'll probably need more logic to sanitize the value for VERSION_AS_NUMBER if you want to use values like x.y.z+a.

  9. azimuthdeveloper commented on Apr 26, 2022

    @azimuthdeveloper

    It's a little hard to believe that Flutter for Windows went stable without this critical feature...

    It is a one-line change in Runner.rc to update the build number. Needing to change the version number in two places instead of one certainly isn't ideal, but "critical feature" substantially overstates the severity here.

    I think it's really important. To that end, would you accept a PR to resolve the issue?

    And, is there somewhere in the Flutter repo you could direct me to, to where this verison is generated?

    Just to give some background - I use the version number of the app to correlate crash logs, and work out if my app needs to be updated or not. It's not really documented well either, so I wasted quite a bit of time trying to figure out why my version didn't come in (when it did automatically on Android and iOS). Not having the version applied would be a non-starter for Android or iOS apps, so I'm not sure why it's aceptable for the Windows platform.

  10. 7 remaining items

  11. loic-sharma commented on Jun 27, 2022

    @loic-sharma
    Member

    Hello! In the next release of Flutter, Windows projects will be able to use the version information from your pubspec.yaml or build arguments. Projects created before the next release of Flutter will need to be updated to get this feature.

  12. Merrit commented on Jun 27, 2022

    @Merrit
    Contributor

    Excellent! 🎉

    Thank you for all your hard work 🙇‍♀️

  13. loic-sharma commented on Jun 27, 2022

    @loic-sharma
  14. loic-sharma commented on Jun 27, 2022

    @loic-sharma
    Member

    @OllyDixon I wouldn't update your project yet as this feature isn't released. That said, what deleted your pubspec.yaml and main.dart files? Running flutter create should not delete or modify files that already exist.

  15. ollyde commented on Jun 27, 2022

    @ollyde

    @loic-sharma Flutter 3.0.3 is release a few days ago? Ah so Flutter 3.0.4 or something, got it :-)

    Running flutter create even with the target resets the core files, have to use git to isolate them.

  16. loic-sharma commented on Jul 15, 2022

    @loic-sharma
    Member

    Added in #106145 and will be available in the next stable release of Flutter.

  17. stuartmorgan-g commented on Jul 15, 2022

    @stuartmorgan-g
    Contributor

    Running flutter create even with the target resets the core files

    @OllyDixon If you have a reproducible case where flutter create deletes or modifies existing files, please file an issue with details.

  18. github-actions commented on Jul 30, 2022

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  19. locked as resolved and limited conversation to collaborators on Jul 30, 2022
  20. loic-sharma commented on Aug 30, 2022

    @loic-sharma
    Member

    Hello everyone, this feature was released today with Flutter 3.3: https://docs.flutter.dev/deployment/windows#updating-the-apps-version-number

    Windows projects that were created before Flutter 3.3 will need to be migrated: https://docs.flutter.dev/development/platform-integration/windows/version-migration

    If you run into any problems, feel free to open a new issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P3Issues that are less important to the Flutter projecta: buildBuilding flutter applications with the toola: desktopRunning on desktopc: new featureNothing broken; request for a new capabilityplatform-windowsBuilding on or for Windows specificallytoolAffects the "flutter" command-line tool. See also t: labels.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions