I want to update my version number in AssemblyInfo.cs with the build number of Azure DevOps (VSTS).
Does anyone know how I can do that through PowerShell?
BuildId) is an internal immutable ID that is also referred to as the Run ID. It is unique across the organization. 2 (The third run will be 3, and so on.) Use $(Rev:r) to ensure that every completed build has a unique name.
AssemblyVersion: Specifies the version of the assembly being attributed. AssemblyFileVersion: Instructs a compiler to use a specific version number for the Win32 file version resource.
You can set the assembly version using the AssemblyVersionAttribute. Assembly attributes are usually applied in the AssemblyInfo.
The best way to do it is with Assembly Info Extension, and use the variable $(Build.BuildNumber)
in the version field.
But if you want to use your own PowerShell script you can do it with this script:
$buildNumber = "$env:Build_BuildNumber"
$pattern = '\[assembly: AssemblyVersion\("(.*)"\)\]'
$AssemblyFiles = Get-ChildItem . AssemblyInfo.cs -rec
foreach ($file in $AssemblyFiles)
{
(Get-Content $file.PSPath) | ForEach-Object{
if($_ -match $pattern){
'[assembly: AssemblyVersion("{0}")]' -f $buildNumber
} else {
# Output line as is
$_
}
} | Set-Content $file.PSPath
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With