小编Ash*_*hra的帖子

使用 powershell 更新程序集信息

我想更新 teamcity checkout 目录中的所有 assemblyinfo.cs。从 AssemblyInfo.cs 中引用了这篇文章Get and Replace AssemblyVersion。看起来缺少某些逻辑并且文件没有得到更新。它应该将行 [assembly: AssemblyVersion("1.4.0.0")] 更新为 [assembly: 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 { …
Run Code Online (Sandbox Code Playgroud)

powershell teamcity

2
推荐指数
1
解决办法
2116
查看次数

字符串比较在 powershell 中不起作用

我正在使用字符串比较在 powershell 中尝试 if else 条件。我按照文档使用 -eq 运算符进行了尝试。但低于错误。这里“Build.Reason”是一个预定义的变量。不知道为什么要为变量寻找 cmdlet 名称。

  Write-Host "$(Build.Reason)"
  if ($(Build.Reason) -eq "Manual" ) {
      $temp = "https://url/api/qualitygates/project_status?&pullRequest=$(Build.Reason)"
      Write-Host "Manual"
  } else {
      Write-Host "CI"
  }
Run Code Online (Sandbox Code Playgroud)

错误

"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\d7af16d6-ce3e-4dec-a636-9447962fdac4.ps1'"
Manual
Manual : The term 'Manual' is not recognized as the name of a cmdlet, function, script file, or operable program. 
Check the spelling of the name, or if a path was included, verify that the path is correct and try …
Run Code Online (Sandbox Code Playgroud)

powershell

1
推荐指数
1
解决办法
97
查看次数

标签 统计

powershell ×2

teamcity ×1