【问题标题】:Updating assembly info using powershell使用 powershell 更新程序集信息
【发布时间】:2018-12-04 03:33:01
【问题描述】:

我想更新 teamcity 结帐目录中的所有 assemblyinfo.cs。引用了这篇文章Get and Replace AssemblyVersion from AssemblyInfo.cs。看起来缺少一些逻辑并且文件没有得到更新。 它应该更新行 [程序集:AssemblyVersion("1.4.0.0")] 到 [程序集:AssemblyVersion("1.4.0.%build.counter%")]

$BuildCounter = "%build.counter%"
$pattern = '\[assembly: AssemblyVersion\("(.*)"\)\]'enter code here
Get-ChildItem -r -filter AssemblyInfo.cs | foreach-object { $name = $_.FullName}
{

(get-content $name ) | ForEach-Object{
    if($_ -match $pattern){
        # We have found the matching line
        # Edit the version number and put back.
        $fileVersion = [version]$matches[1]
        $newVersion = "{0}.{1}.{2}.{3}" -f $fileVersion.Major, $fileVersion.Minor, $fileVersion.Build, $BuildCounter 
        '[assembly: AssemblyVersion("{0}")]' -f $newVersion
    } else {
        # Output line as is
        $_
    }
} | Set-Content $name

}`enter code here`

【问题讨论】:

    标签: powershell teamcity


    【解决方案1】:

    没关系,刚刚开始工作,看起来像语法问题

    $BuildCounter = "build.counter"
    $pattern = '\[assembly: AssemblyVersion\("(.*)"\)\]'
    $AssemblyFiles = Get-ChildItem . AssemblyInfo.cs -rec
    
    
    foreach ($file in $AssemblyFiles)
    
    {
    
    (Get-Content $file.PSPath) | ForEach-Object{
        if($_ -match $pattern){
            # We have found the matching line
            # Edit the version number and put back.
            $fileVersion = [version]$matches[1]
            $newVersion = "{0}.{1}.{2}.{3}" -f $fileVersion.Major, $fileVersion.Minor, $fileVersion.Build, $BuildCounter 
            '[assembly: AssemblyVersion("{0}")]' -f $newVersion
        } else {
            # Output line as is
            $_
        }
    } | Set-Content $file.PSPath
    
    }
    Write-Host "##teamcity[buildNumber '$newVersion']"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-02
      • 2010-09-18
      • 2019-01-07
      • 2023-02-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多