On our build server, I'm adding the build number to the AssemblyInfo.cs file. The script finds the current version in the AssemblyInfo.cs file, then appends the build number, then overwrites the version value. Here's the code:
$oldValue = (Get-Content .\\AssemblyInfo.cs | Select-String -pattern
"AssemblyVersion").Line.Split('"')[1]
$newValue = $oldValue + "." + $Env:BUILD_NUMBER
(Get-Content .\\AssemblyInfo.cs).replace($oldValue, $newValue) | Set-Content .\\AssemblyInfo.cs
I want to make an sh script that does the same thing. I'm able to pull out the version into a variable and print it using these lines:
export server_version=`grep AssemblyVersion AssemblyInfo.cs | awk '{split($0,a,"\\""); print a[2]}'| sed "s/'//g" | awk '{$1=$1;print}'`
echo Server version is ${server_version}
sed -i 's/${server_version}/${server_version}.${BUILD_NUMBER}/g' AssemblyInfo.cs
However, I haven't had any luck of overwriting the AssemblyVersion. Any help would be appreciated!
EDIT, adding input/expected output:
Here is example of AssemblyInfo.cs:
[assembly: AssemblyVersion("0.3.0")]
Then after script where the environment variable build number is another number (Let's say 5 for this example), expected output:
[assembly: AssemblyVersion("0.3.0.5")]
You only need sed
:
BUILD_NUMBER=6; sed -iE "s/(\[assembly: AssemblyVersion\(\")(.*)(\"\)\])/\1\2.${BUILD_NUMBER}\3/" AssemblyInfo.cs
a bit confusing because you have to escape some things, but it works.