PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, October 9, 2022

[FIXED] How can I update AssemblyVersion number in AssemblyInfo.cs with build number of Azure DevOps via PowerShell?

 October 09, 2022     azure-devops, azure-pipelines, continuous-deployment, continuous-integration, powershell     No comments   

Issue

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?


Solution

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

}


Answered By - Shayki Abramczyk
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing