Repository navigation
[Windows] support pubspec.yaml version/build number in windows projects #73652
Copy link
Copy link
Closed
getsentry/sentry-docs
#7155Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projecta: buildBuilding flutter applications with the toolBuilding flutter applications with the toola: desktopRunning on desktopRunning on desktopc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityplatform-windowsBuilding on or for Windows specificallyBuilding on or for Windows specificallytoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.
Description
Steps to Reproduce
flutter config --enable-windows-desktop- create a new project and run
flutter build windows, the built exe version should be 1.0.0.0 - change version in
pubspec.yamlfrom1.0.0+1to any other version like1.1.1+2 pub getand build again, the version of exe is still1.0.0.0flutter cleandoesn'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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projecta: buildBuilding flutter applications with the toolBuilding flutter applications with the toola: desktopRunning on desktopRunning on desktopc: new featureNothing broken; request for a new capabilityNothing broken; request for a new capabilityplatform-windowsBuilding on or for Windows specificallyBuilding on or for Windows specificallytoolAffects the "flutter" command-line tool. See also t: labels.Affects the "flutter" command-line tool. See also t: labels.
Activity
stuartmorgan-g commentedon Jan 10, 2021
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.
[-][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[/+]fzyzcjy commentedon Mar 5, 2022
azimuthdeveloper commentedon Apr 24, 2022
It's a little hard to believe that Flutter for Windows went stable without this critical feature...
Sunbreak commentedon Apr 24, 2022
Try flutter_distributor according to fastforgedev/fastforge#65
stuartmorgan-g commentedon Apr 25, 2022
It is a one-line change in
Runner.rcto 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.jmatth commentedon Apr 25, 2022
Here are the Github Actions steps I'm using to replace the build number as part of the Windows build process:
Note that it assumes the version number extracted from
pubspec.yamlis in the formx.y.z. You'll probably need more logic to sanitize the value forVERSION_AS_NUMBERif you want to use values likex.y.z+a.azimuthdeveloper commentedon Apr 26, 2022
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.
7 remaining items
Add more CMake unit tests (#106076)
Add integration test for `flutter build windows` (#106053)
[Windows] Flow version information to the build output (#106145)
loic-sharma commentedon Jun 27, 2022
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.
Merrit commentedon Jun 27, 2022
Excellent! 🎉
Thank you for all your hard work 🙇♀️
loic-sharma commentedon Jun 27, 2022
loic-sharma commentedon Jun 27, 2022
@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 createshould not delete or modify files that already exist.ollyde commentedon Jun 27, 2022
@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.
loic-sharma commentedon Jul 15, 2022
Added in #106145 and will be available in the next stable release of Flutter.
stuartmorgan-g commentedon Jul 15, 2022
@OllyDixon If you have a reproducible case where
flutter createdeletes or modifies existing files, please file an issue with details.github-actions commentedon Jul 30, 2022
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 -vand a minimal reproduction of the issue.loic-sharma commentedon Aug 30, 2022
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!