I have a multi plattform project in Xamarin
. The Version Number for each .csproj
Project (iOS, Android, Mac, Windows) The Version number is set from the .sln
Solution options.
My problem now is to retrieve the version number from the solution file without having access to the individual Projects.
I know that there are solutions to get the Version number from like NSBundle
in iOS and similar in other platforms, however I can't use those.
EDIT: This is the structure of my Solution called ETCS
(git branch develop). There I have a Project ETCS
which is the core funtions and the Projects ETCS.***
, one for each platform.
The version number is set in the solution from where the projects get that number. See image below. What I need is a way to set a constant
in the core function project.
A solution (
.sln
) is a plain text file, no xml, json, etc.. so you can parse it however you want.If you add a version via Visual Studio for Mac/MonoDevelop/Xamarin Studio you end up with a
GlobalSection
in the.sln
of:Note: The solution
metaproj
produced viaMSBuildEmitSolution=1
does not contain this information, so you can not use built-in MSBuild features to parse it.Parse the version out (using bash here, but use your own choice to tool(s):
Now you have the version (in an env. variable in this example).
If you have a
.cs
file (Global.Template
) that looks like this:You can replace
SushiHangover
with the solution based version:Results in: