简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM