Anjali Iyengar
Anjali Iyengar

Reputation: 360

Modify the .exe's AssemblyInfo using PowerShell in TFS 2018 build

I want to use PowerShell to update my application's Assembly info like Product Name, File Description in TFS vNext build. I want to use build variables in build definition and pass it to the script.

I have done the same to update version number with the help of this(https://writeabout.net/2015/11/01/set-assembly-and-app-version-to-a-matching-build-name-in-tfs-2015-or-vso-build-vnext/).

I need help with the script to replace "Product Name" or "Description" value with new value.

Upvotes: 1

Views: 479

Answers (1)

Shayki Abramczyk
Shayki Abramczyk

Reputation: 41815

You can replace the name & description with a small script:

Param(
    [string]$filePath,
    [string]$newProductName,
    [string]$newProductDesc
)

$patternProductName = '\[assembly: AssemblyProduct\("(.*)"\)\]'
$patternProductDesc = '\[assembly: AssemblyDescription\("(.*)"\)\]'
(Get-Content $filePath) | ForEach-Object{
     if($_ -match $patternProductName){
           '[assembly: AssemblyProduct("{0}")]' -f $newProductName
     }
     elseif($_ -match $patternProductDesc){
           '[assembly: AssemblyDescription("{0}")]' -f $newProductDesc 
     }
     else{
        $_
     }
} | Set-Content $filePath

Now during the build call this script and in the arguments send the 3 args: AssmeblyInfo file path, your new product name and your new product description.

Upvotes: 2

Related Questions