title: Updating assembly info using powershell
body: <p>I want to update all assemblyinfo.cs in teamcity checkout directory. Referred this post <a href="https://stackoverflow.com/questions/36200323/get-and-replace-assemblyversion-from-assemblyinfo-cs">Get and Replace AssemblyVersion from AssemblyInfo.cs</a>. Looks like some logic is missing and file is not getting updated. 
  It should update line 
  [assembly: AssemblyVersion("1.4.0.0")] to
  [assembly: AssemblyVersion("1.4.0.%build.counter%")]</p>
  
  <pre><code>$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`
  </code></pre>