我正在尝试创建一个脚本,该脚本将从解决方案中找到并返回程序集版本。它涵盖了一些测试场景,但我找不到正确的正则表达式来检查版本的格式是否正确(1.0.0.0 可以,但是 1.0.o.0)并且包含 4 位数字?这是我的代码。
function Get-Version-From-SolutionInfo-File($path="$pwd\SolutionInfo.cs"){
$RegularExpression = [regex] 'AssemblyVersion\(\"(.*)\"\)'
$fileContent = Get-Content -Path $path
foreach($content in $fileContent)
{
$match = [System.Text.RegularExpressions.Regex]::Match($content, $RegularExpression)
if($match.Success) {
$match.groups[1].value
}
}
}