powershell - 使用 powershell 更新程序集信息
问题描述
我想更新 teamcity 结帐目录中的所有 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 {
# Output line as is
$_
}
} | Set-Content $name
}`enter code here`
解决方案
没关系,刚刚开始工作,看起来像语法问题
$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']"
推荐阅读
- slim - 在 Slim 框架中,什么是容器,它的用途是什么?
- flutter - Flutter FutureBuilder 并使用 Navigator.pushNamed 导航到不同的路线
- javascript - 如何分离突出显示的对象 JavaScript
- javascript - 如何根据 div 的样式使用 jquerySelectorAll
- xml - 在 xml 文件中自动生成用于 Omnett++ 模拟的环境对象
- mysql - INNER JOIN 结合 2 列
- javascript - ReactJS中componentDidMount内的多个api调用中的多个设置状态
- node.js - Angular - 如何在不创建nodejs服务器的情况下引用客户端本地activex dll
- sitecore - 如何从顶级 1st 父 ID Sitecore RESTful API 获取 3rd 级子项详细信息
- java - 为什么这个类方法返回'null'?