question

JohanSchoeman-1539 avatar image
0 Votes"
JohanSchoeman-1539 asked RobCaplan edited

Update iOS bundle version after build with Custom Command on VS2019 for Mac

I have a custom command running on my Win10 Dev machine's VS2019 that increments the AssemblyFileversion and append the new v number to a buildlog.txt file for reference. I wish to have my vs2019 on Macos do the same for a XamarinForms Solution, but either my google-fu skills are fading or no-one has documented doing it. I particularly want the post-build event to up date the Bundle Version value in the plist file for the iOS project.


Is there anywhere I can find some info on this challenge?

dotnet-xamarinvs-msbuild
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

JohanSchoeman-1539 avatar image
0 Votes"
JohanSchoeman-1539 answered

OK, got it working myself:
First realise the custom commands in VS for Mac will be UNIX commands or bash commands.

This was the knowledge I needed to actually make this work.

In VS2019, right-click on the iOS project, select Options -> Build -> Custom Commands

Selected a build event, I chose After Build

Command:

sh ./BuildCmd.sh BuildLog.txt ${ProjectConfigPlat} ${ProjectConfigName}

Working Directory:

${ProjectDir}

Run on external Console is [Checked]
All else left as default

I created an external bash file called BuildCmd.sh to concatenate a few values and write them to a text file I call BuildLog.txt in the iOS project folder. No special permissions given to any file or folder for this to work.
The Bash file contents:


 !/bin/bash
 # A simple copy script
 FILE_NAME=$1
 CONFIG=$2
 PLATFORM=$3
 current_time=$(date "+%Y-%m-%d %H:%M:%S")
 build_time=$(date "+%Y%m.%d%H%M")
    
 LOGLINE=$current_time
 LOGLINE+="  "
 LOGLINE+=$CONFIG
 LOGLINE+="  "
 LOGLINE+=$PLATFORM
 LOGLINE+="  "
 LOGLINE+=$build_time
    
 # write the above to the build log file
 echo $LOGLINE >> $FILE_NAME
    
    
 plutil -replace CFBundleVersion -string $build_time Info.plist





Machine runs Catalina, VS2019 is v8.10
Xamarin Forms Solution
105338-buildlog.txt



buildlog.txt (94 B)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.