Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by thrmotta · Dec 16, 2014 at 09:12 PM · c#monodevelopversionassemblygit

How to increment a Version string everytime Unity is built?

Hello!

Im currently facing a problem where I need to have a string with the current version of my application and this needs to change automatically every time Unity is built. After some research Ive come across the following tag:

 [assembly:AssemblyVersion ("1.0.*.*")]

But this only seems to work at the AssemblyInfo.cs file, which my .csproj isnt making, so my next step was to manually change this .csproj to include the creation of the .cs, following this article. This didnt work since everytime I run Unity this file will just get rewritten.

As a side note, Im using Mono for coding and GIT for version control, so the perfect world here would be to use GIT Revision as part of the version string I need, which should be something similar to what I found here, which uses Hudson and SVN.

So, how can I make this work? What am I missing?

Thank you!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by BMayne · Dec 16, 2014 at 09:23 PM

Hey There,

It's not that hard to do this since your script are just a text file to Unity.

1) Use AssetDatabase to find the script

2) Read the file into a string.

3) Use string functions to replace the Version number.

4) Use File.WriteAll() to write the content back to the file you started off with.

5) AssetDatabase.Refresh();

Regards,

Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image thrmotta · Dec 16, 2014 at 09:32 PM 0
Share

I havent tested this out yet, although I do believe this is gonna work, but I have to say.. this looks nasty haha

Ill give it a try! Thanks!

avatar image BMayne · Dec 16, 2014 at 10:47 PM 0
Share

Don't worry. It's basically just a super simple version of a T4 Template (a code generator). It can be very useful in a project to have code that generates code. It makes it much harder to make a mistake.

avatar image gjf · Dec 17, 2014 at 01:04 PM 2
Share

take a look at this thread, or for something incredibly naive (if you don't need the version number accessible within the build); probably not what you want, but maybe others stumbling on this page might find it useful.

 [$$anonymous$$enuItem("SSG/Build iOS Development", false, 10)]
 public static void CustomBuild()
 {
     BumpBundleVersion();
     BuildPipeline.BuildPlayer(null, "iOS", BuildTarget.iPhone, BuildOptions.Development); 
 }
 
 // Bump version number in PlayerSettings.bundleVersion
 private static void BumpBundleVersion()
 {
     float versionFloat;
 
     if (float.TryParse(PlayerSettings.bundleVersion, out versionFloat))
     {
         versionFloat += 0.01f;
         PlayerSettings.bundleVersion = versionFloat.ToString();
     }
 }


avatar image thrmotta · Dec 18, 2014 at 07:12 PM 1
Share

Doesnt this only works for IOS/Android?

Btw, the solution @B$$anonymous$$ayne described worked like a charm!

Thanks!

avatar image BMayne · Dec 18, 2014 at 07:16 PM 0
Share

You can also just hook up to the PostProcessBuild

 [PostProcessBuild]
 public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) 
 {
   //A new build has happened so lets increase our version number
 }

The advantage here is the fact that you know this will be called even if you don't have a custom menu entry. This happens after a build but should be fine.

Show more comments
avatar image
1

Answer by pdwitte · Nov 08, 2016 at 07:55 AM

As of the latest version most applications above no longer work.

Wrote and tested a script that does it for you for Android and iOS (free). Leave a star if it works :-)

https://github.com/PimDeWitte/Unity-auto-version-increment

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by SilentSin · Feb 17, 2016 at 08:01 AM

Weaver (https://www.assetstore.unity3d.com/en/#!/content/60305) has an AppDetails script which gives you automatic build numbering (as an int), as well as a build time stamp (as a DateTime).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

31 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

After upgrading to 3.4 I sync Monodevlop and now I have 4 different projects in my solution 1 Answer

MonoDevelop C# Assembly problem: UnityEngine does not exist in current context. 1 Answer

Weird rotation Log that makes no sense ? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges