Przeglądaj źródła

一致方法获取版本号

黄中银 2 tygodni temu
rodzic
commit
d90aafeb85

+ 26 - 1
Directory.Build.props

@@ -23,11 +23,36 @@
   <PropertyGroup>
     <Description>变更冒泡事件库,支持 Rx 响应式流、弱引用消息和可插拔调度环境</Description>
     <PackageTags>change-bubbling;reactive;rx;mvvm;messaging;event;observable</PackageTags>
+    <PackageReadmeFile>README.md</PackageReadmeFile>
   </PropertyGroup>
 
+  <!-- 从 versions 目录自动获取版本号 -->
+  <PropertyGroup>
+    <VersionsDir>$([System.IO.Path]::Combine($(MSBuildThisFileDirectory), 'versions'))</VersionsDir>
+    <VersionPattern>v(\d+)\.(\d+)\.(\d+)</VersionPattern>
+    <DetectedVersion>1.0.0</DetectedVersion>
+  </PropertyGroup>
+
+  <Target Name="DetectVersionFromFiles" BeforeTargets="GetAssemblyVersion;GenerateNuspec;Pack;Build">
+    <ItemGroup>
+      <VersionFiles Include="$(VersionsDir)\v*.md" />
+    </ItemGroup>
+    <PropertyGroup>
+      <_VersionFileList>@(VersionFiles->'%(Filename)', ',')</_VersionFileList>
+    </PropertyGroup>
+    <Exec Command="powershell -NoProfile -Command &quot;$files = '$(_VersionFileList)' -split ','; $versions = $files | Where-Object { $_ -match '^v(\d+)\.(\d+)\.(\d+)' } | ForEach-Object { [PSCustomObject]@{Name=$_; V=[version]($_ -replace '^v(\d+\.\d+\.\d+).*','$1')} } | Sort-Object V -Descending; if($versions) { $versions[0].Name -replace '^v(\d+\.\d+\.\d+).*','$1' } else { '1.0.0' }&quot;"
+          ConsoleToMsBuild="true"
+          Condition="'$(_VersionFileList)' != ''">
+      <Output TaskParameter="ConsoleOutput" PropertyName="DetectedVersion" />
+    </Exec>
+    <PropertyGroup Condition="'$(DetectedVersion)' != ''">
+      <Version>$(DetectedVersion)</Version>
+    </PropertyGroup>
+  </Target>
+
   <!-- NuGet 包公共元数据 -->
   <PropertyGroup>
-    <Version>0.0.1-beta5</Version>
+    <Version>$(DetectedVersion)</Version>
     <Authors>Apq</Authors>
     <Company>Apq</Company>
     <Copyright>Copyright © Apq $([System.DateTime]::Now.Year)</Copyright>

+ 0 - 19
buildTools/bump-version.bat

@@ -1,19 +0,0 @@
-@echo off
-chcp 65001 >nul
-title Apq.ChangeBubbling 版本号自动增长工具
-
-:: 获取脚本所在目录
-set "SCRIPT_DIR=%~dp0"
-
-:: 检查是否提供了参数
-if "%~1"=="" (
-    :: 无参数,交互式运行
-    powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_DIR%bump-version.ps1"
-) else (
-    :: 有参数,传递给 PowerShell
-    if "%~2"=="" (
-        powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_DIR%bump-version.ps1" -Part "%~1"
-    ) else (
-        powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_DIR%bump-version.ps1" -Part "%~1" -Suffix "%~2"
-    )
-)

+ 0 - 165
buildTools/bump-version.ps1

@@ -1,165 +0,0 @@
-# bump-version.ps1
-param(
-    [ValidateSet('major', 'minor', 'patch')]
-    [string]$Part,
-    [string]$Suffix
-)
-
-$ErrorActionPreference = 'Stop'
-$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
-$ProjectRoot = Split-Path -Parent $ScriptDir
-$PropsFile = Join-Path $ProjectRoot 'Directory.Build.props'
-$SetVersionScript = Join-Path $ScriptDir 'set-version.ps1'
-
-function Write-ColorText {
-    param([string]$Text, [string]$Color = 'White')
-    Write-Host $Text -ForegroundColor $Color
-}
-
-# 读取单个按键输入,按Q立即退出
-function Read-KeyOrInput {
-    param([string]$Prompt)
-    Write-Host $Prompt -NoNewline
-    $input = ''
-    while ($true) {
-        $key = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
-        if ($key.Character -eq 'q' -or $key.Character -eq 'Q') {
-            Write-Host ''
-            Write-ColorText '已退出' 'Yellow'
-            exit 0
-        }
-        if ($key.VirtualKeyCode -eq 13) {  # Enter
-            Write-Host ''
-            return $input
-        }
-        if ($key.VirtualKeyCode -eq 8) {  # Backspace
-            if ($input.Length -gt 0) {
-                $input = $input.Substring(0, $input.Length - 1)
-                Write-Host "`b `b" -NoNewline
-            }
-        } elseif ($key.Character -match '[\x20-\x7E]') {
-            $input += $key.Character
-            Write-Host $key.Character -NoNewline
-        }
-    }
-}
-
-# 读取单个选择键
-function Read-Choice {
-    param([string]$Prompt, [string[]]$ValidKeys)
-    Write-Host $Prompt -NoNewline
-    while ($true) {
-        $key = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
-        if ($key.Character -eq 'q' -or $key.Character -eq 'Q') {
-            Write-Host ''
-            Write-ColorText '已退出' 'Yellow'
-            exit 0
-        }
-        $char = $key.Character.ToString()
-        if ($ValidKeys -contains $char -or $key.VirtualKeyCode -eq 13) {
-            Write-Host $char
-            return $char
-        }
-    }
-}
-
-Write-ColorText "`n========================================" 'Cyan'
-Write-ColorText '  Apq.ChangeBubbling 版本号自动增长工具' 'Cyan'
-Write-ColorText "========================================" 'Cyan'
-Write-ColorText '  按 Q 随时退出' 'DarkGray'
-Write-ColorText "========================================`n" 'Cyan'
-
-if (-not (Test-Path $SetVersionScript)) {
-    Write-ColorText '错误: 找不到 set-version.ps1 文件' 'Red'
-    Write-ColorText "路径: $SetVersionScript" 'Red'
-    exit 1
-}
-
-if (-not (Test-Path $PropsFile)) {
-    Write-ColorText '错误: 找不到 Directory.Build.props 文件' 'Red'
-    Write-ColorText "路径: $PropsFile" 'Red'
-    exit 1
-}
-
-$fileContent = Get-Content $PropsFile -Raw -Encoding UTF8
-if ($fileContent -match '<Version>([^<]+)</Version>') {
-    $currentVersionFull = $Matches[1]
-    if ($currentVersionFull -match '^(\d+\.\d+\.\d+)(-(.+))?$') {
-        $currentVersion = $Matches[1]
-        $currentSuffix = $Matches[3]
-    } else {
-        Write-ColorText "错误: 无法解析版本号格式: $currentVersionFull" 'Red'
-        exit 1
-    }
-    Write-ColorText "当前版本: $currentVersionFull" 'Yellow'
-} else {
-    Write-ColorText '错误: 无法读取当前版本号' 'Red'
-    exit 1
-}
-
-$versionParts = $currentVersion.Split('.')
-$major = [int]$versionParts[0]
-$minor = [int]$versionParts[1]
-$patch = [int]$versionParts[2]
-
-if ([string]::IsNullOrWhiteSpace($Part)) {
-    Write-Host ''
-    Write-ColorText '请选择要增长的版本部分:' 'White'
-    Write-ColorText "  [1] Major (主版本号): $major.0.0 -> $($major + 1).0.0" 'Gray'
-    Write-ColorText "  [2] Minor (次版本号): $major.$minor.0 -> $major.$($minor + 1).0" 'Gray'
-    Write-ColorText "  [3] Patch (修订号):   $major.$minor.$patch -> $major.$minor.$($patch + 1)" 'Gray'
-    Write-Host ''
-
-    $choice = Read-Choice '请选择 (1/2/3,默认为 3): ' @('1', '2', '3')
-
-    switch ($choice) {
-        '1' { $Part = 'major' }
-        '2' { $Part = 'minor' }
-        default { $Part = 'patch' }
-    }
-}
-
-switch ($Part) {
-    'major' {
-        $major++
-        $minor = 0
-        $patch = 0
-    }
-    'minor' {
-        $minor++
-        $patch = 0
-    }
-    'patch' {
-        $patch++
-    }
-}
-
-$newVersion = "$major.$minor.$patch"
-
-if (-not $PSBoundParameters.ContainsKey('Suffix')) {
-    Write-Host ''
-    Write-ColorText '是否添加预发布后缀? (留空保留现有后缀,输入 clear 清除)' 'Gray'
-    Write-ColorText '  示例: alpha1, beta1, rc1, preview1' 'Gray'
-    if ($currentSuffix) {
-        Write-ColorText "  当前后缀: $currentSuffix" 'Yellow'
-    }
-    $Suffix = Read-KeyOrInput '预发布后缀: '
-}
-
-if ($Suffix -eq 'clear') {
-    $finalSuffix = ''
-} elseif ([string]::IsNullOrWhiteSpace($Suffix)) {
-    $finalSuffix = $currentSuffix
-} else {
-    $finalSuffix = $Suffix
-}
-
-Write-Host ''
-Write-ColorText '即将调用 set-version.ps1 设置新版本...' 'Cyan'
-Write-Host ''
-
-if ([string]::IsNullOrWhiteSpace($finalSuffix)) {
-    & $SetVersionScript -Version $newVersion
-} else {
-    & $SetVersionScript -Version $newVersion -Suffix $finalSuffix
-}

+ 34 - 13
buildTools/pack-release.ps1

@@ -7,7 +7,7 @@ param(
 $ErrorActionPreference = 'Stop'
 $ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
 $ProjectRoot = Split-Path -Parent $ScriptDir
-$PropsFile = Join-Path $ProjectRoot 'Directory.Build.props'
+$VersionsDir = Join-Path $ProjectRoot 'versions'
 $DefaultOutputDir = Join-Path $ProjectRoot 'nupkgs'
 
 function Write-ColorText {
@@ -26,7 +26,7 @@ function Read-Confirm {
             Write-ColorText '已退出' 'Yellow'
             exit 0
         }
-        if ($key.Character -eq 'y' -or $key.Character -eq 'Y') {
+        if ($key.Character -eq 'y' -or $key.Character -eq 'Y' -or $key.VirtualKeyCode -eq 13) {
             Write-Host 'Y'
             return $true
         }
@@ -43,22 +43,32 @@ Write-ColorText "========================================" 'Cyan'
 Write-ColorText '  按 Q 随时退出' 'DarkGray'
 Write-ColorText "========================================`n" 'Cyan'
 
-if (-not (Test-Path $PropsFile)) {
-    Write-ColorText '错误: 找不到 Directory.Build.props 文件' 'Red'
-    Write-ColorText "路径: $PropsFile" 'Red'
+if (-not (Test-Path $VersionsDir)) {
+    Write-ColorText '错误: 找不到 versions 目录' 'Red'
+    Write-ColorText "路径: $VersionsDir" 'Red'
     exit 1
 }
 
-# 读取当前版本
-$fileContent = Get-Content $PropsFile -Raw -Encoding UTF8
-if ($fileContent -match '<Version>([^<]+)</Version>') {
-    $currentVersion = $Matches[1]
-    Write-ColorText "当前版本: $currentVersion" 'Yellow'
-} else {
-    Write-ColorText '错误: 无法读取当前版本号' 'Red'
+# 从 versions 目录获取版本号(与 Directory.Build.props 保持一致)
+$versionFiles = @(Get-ChildItem -Path $VersionsDir -Filter 'v*.md' -ErrorAction SilentlyContinue)
+$versions = @($versionFiles | Where-Object { $_.BaseName -match '^v(\d+)\.(\d+)\.(\d+)' } | ForEach-Object {
+    $fullVersion = $_.BaseName -replace '^v', ''
+    $baseVersion = $_.BaseName -replace '^v(\d+\.\d+\.\d+).*', '$1'
+    [PSCustomObject]@{
+        Name = $fullVersion
+        Version = [version]$baseVersion
+    }
+} | Sort-Object Version -Descending)
+
+if ($versions.Count -eq 0) {
+    Write-ColorText '错误: 无法从 versions 目录获取版本号' 'Red'
+    Write-ColorText '请确保 versions 目录中存在 v*.*.*.md 格式的版本文件' 'Red'
     exit 1
 }
 
+$currentVersion = $versions[0].Name
+Write-ColorText "当前版本: $currentVersion" 'Yellow'
+
 # 设置输出目录
 if ([string]::IsNullOrWhiteSpace($OutputDir)) {
     $OutputDir = $DefaultOutputDir
@@ -71,7 +81,7 @@ Write-Host ''
 Write-ColorText "输出目录: $OutputDir" 'Gray'
 Write-Host ''
 
-if (-not (Read-Confirm '确认开始打包? (Y/N): ')) {
+if (-not (Read-Confirm '确认开始打包? ([Y]/N): ')) {
     Write-ColorText '已取消' 'Yellow'
     exit 0
 }
@@ -86,6 +96,17 @@ Write-Host ''
 Write-ColorText '开始打包...' 'Cyan'
 Write-Host ''
 
+# 删除当前版本的旧包(避免 NuGet 缓存冲突)
+$oldPackages = Get-ChildItem -Path $OutputDir -Filter "Apq.ChangeBubbling*.$currentVersion.*pkg" -ErrorAction SilentlyContinue
+if ($oldPackages.Count -gt 0) {
+    Write-ColorText "清理当前版本 ($currentVersion) 的旧包..." 'Gray'
+    foreach ($pkg in $oldPackages) {
+        Remove-Item $pkg.FullName -Force
+        Write-ColorText "  已删除: $($pkg.Name)" 'DarkGray'
+    }
+    Write-Host ''
+}
+
 # 构建打包参数 - 只打包主项目
 $ProjectPath = Join-Path $ProjectRoot 'Apq.ChangeBubbling\Apq.ChangeBubbling.csproj'
 $packArgs = @(

+ 0 - 19
buildTools/set-version.bat

@@ -1,19 +0,0 @@
-@echo off
-chcp 65001 >nul
-title Apq.ChangeBubbling 版本号设置工具
-
-:: 获取脚本所在目录
-set "SCRIPT_DIR=%~dp0"
-
-:: 检查是否提供了参数
-if "%~1"=="" (
-    :: 无参数,交互式运行
-    powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_DIR%set-version.ps1"
-) else (
-    :: 有参数,传递给 PowerShell
-    if "%~2"=="" (
-        powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_DIR%set-version.ps1" -Version "%~1"
-    ) else (
-        powershell -NoProfile -ExecutionPolicy Bypass -File "%SCRIPT_DIR%set-version.ps1" -Version "%~1" -Suffix "%~2"
-    )
-)

+ 0 - 181
buildTools/set-version.ps1

@@ -1,181 +0,0 @@
-# set-version.ps1
-param(
-    [string]$Version,
-    [string]$Suffix
-)
-
-$ErrorActionPreference = 'Stop'
-$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
-$ProjectRoot = Split-Path -Parent $ScriptDir
-$PropsFile = Join-Path $ProjectRoot 'Directory.Build.props'
-
-function Write-ColorText {
-    param([string]$Text, [string]$Color = 'White')
-    Write-Host $Text -ForegroundColor $Color
-}
-
-# 读取单个按键输入,按Q立即退出
-function Read-KeyOrInput {
-    param([string]$Prompt)
-    Write-Host $Prompt -NoNewline
-    $input = ''
-    while ($true) {
-        $key = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
-        if ($key.Character -eq 'q' -or $key.Character -eq 'Q') {
-            Write-Host ''
-            Write-ColorText '已退出' 'Yellow'
-            exit 0
-        }
-        if ($key.VirtualKeyCode -eq 13) {  # Enter
-            Write-Host ''
-            return $input
-        }
-        if ($key.VirtualKeyCode -eq 8) {  # Backspace
-            if ($input.Length -gt 0) {
-                $input = $input.Substring(0, $input.Length - 1)
-                Write-Host "`b `b" -NoNewline
-            }
-        } elseif ($key.Character -match '[\x20-\x7E]') {
-            $input += $key.Character
-            Write-Host $key.Character -NoNewline
-        }
-    }
-}
-
-# 读取 Y/N 确认,按Q立即退出
-function Read-Confirm {
-    param([string]$Prompt, [bool]$DefaultYes = $false)
-    Write-Host $Prompt -NoNewline
-    while ($true) {
-        $key = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown')
-        if ($key.Character -eq 'q' -or $key.Character -eq 'Q') {
-            Write-Host ''
-            Write-ColorText '已退出' 'Yellow'
-            exit 0
-        }
-        if ($key.Character -eq 'y' -or $key.Character -eq 'Y') {
-            Write-Host 'Y'
-            return $true
-        }
-        if ($key.Character -eq 'n' -or $key.Character -eq 'N') {
-            Write-Host 'N'
-            return $false
-        }
-        if ($key.VirtualKeyCode -eq 13) {  # Enter - 使用默认值
-            if ($DefaultYes) {
-                Write-Host 'Y'
-                return $true
-            } else {
-                Write-Host 'N'
-                return $false
-            }
-        }
-    }
-}
-
-Write-ColorText "`n========================================" 'Cyan'
-Write-ColorText '  Apq.ChangeBubbling 版本号设置工具' 'Cyan'
-Write-ColorText "========================================" 'Cyan'
-Write-ColorText '  按 Q 随时退出' 'DarkGray'
-Write-ColorText "========================================`n" 'Cyan'
-
-if (-not (Test-Path $PropsFile)) {
-    Write-ColorText '错误: 找不到 Directory.Build.props 文件' 'Red'
-    Write-ColorText "路径: $PropsFile" 'Red'
-    exit 1
-}
-
-$fileContent = Get-Content $PropsFile -Raw -Encoding UTF8
-if ($fileContent -match '<Version>([^<]+)</Version>') {
-    $currentVersion = $Matches[1]
-    Write-ColorText "当前版本: $currentVersion" 'Yellow'
-} else {
-    Write-ColorText '警告: 无法读取当前版本号' 'Yellow'
-    $currentVersion = '未知'
-}
-
-if ([string]::IsNullOrWhiteSpace($Version)) {
-    Write-Host ''
-    do {
-        $Version = Read-KeyOrInput '请输入新版本号 (X.X.X 格式): '
-        if ([string]::IsNullOrWhiteSpace($Version)) {
-            Write-ColorText '版本号不能为空,请重新输入' 'Yellow'
-        }
-    } while ([string]::IsNullOrWhiteSpace($Version))
-}
-
-# 严格验证 X.X.X 格式
-if ($Version -notmatch '^[0-9]+\.[0-9]+\.[0-9]+$') {
-    Write-ColorText '错误: 版本号格式不正确,必须为 X.X.X 格式 (例如: 1.0.0)' 'Red'
-    exit 1
-}
-
-if ([string]::IsNullOrWhiteSpace($Suffix)) {
-    Write-Host ''
-    Write-ColorText '是否添加预发布后缀? (留空跳过)' 'Gray'
-    Write-ColorText '  示例: alpha1, beta1, rc1, preview1' 'Gray'
-    $Suffix = Read-KeyOrInput '预发布后缀: '
-}
-
-if ([string]::IsNullOrWhiteSpace($Suffix)) {
-    $fullVersion = $Version
-} else {
-    if ($Suffix -notmatch '^[a-zA-Z][a-zA-Z0-9]*$') {
-        Write-ColorText '错误: 后缀格式不正确' 'Red'
-        exit 1
-    }
-    $fullVersion = "$Version-$Suffix"
-}
-
-Write-Host ''
-Write-ColorText "新版本号: $fullVersion" 'Green'
-Write-Host ''
-
-if (-not (Read-Confirm '确认更新版本号? (Y/N): ')) {
-    Write-ColorText '已取消' 'Yellow'
-    exit 0
-}
-
-try {
-    $newContent = $fileContent -replace '<Version>[^<]+</Version>', "<Version>$fullVersion</Version>"
-    $utf8NoBom = New-Object System.Text.UTF8Encoding $false
-    [System.IO.File]::WriteAllText($PropsFile, $newContent, $utf8NoBom)
-
-    Write-Host ''
-    Write-ColorText "版本号已更新: $currentVersion -> $fullVersion" 'Green'
-    Write-Host ''
-    Write-ColorText '受影响的 NuGet 包:' 'Cyan'
-    Write-ColorText '  - Apq.ChangeBubbling' 'White'
-    Write-Host ''
-
-    # 询问是否生成新版本包
-    $doPack = Read-Confirm '是否生成新版本包? (Y/n,默认为 Y): ' $true
-
-    if ($doPack) {
-        Write-Host ''
-        Write-ColorText '开始生成新版本包...' 'Cyan'
-        Write-Host ''
-
-        $PackScript = Join-Path $ScriptDir 'pack-release.ps1'
-        & $PackScript
-
-        if ($LASTEXITCODE -eq 0) {
-            Write-Host ''
-            Write-ColorText '下一步操作:' 'Yellow'
-            Write-ColorText '  推送 tag 触发自动发布: git tag v' -NoNewline 'Gray'
-            Write-ColorText $fullVersion -NoNewline 'White'
-            Write-ColorText ' && git push origin v' -NoNewline 'Gray'
-            Write-ColorText $fullVersion 'White'
-            Write-Host ''
-        }
-    } else {
-        Write-ColorText '下一步操作:' 'Yellow'
-        Write-ColorText '  1. 运行 pack-release.bat 生成新版本包' 'Gray'
-        Write-ColorText '  2. 推送 tag 触发自动发布' 'Gray'
-        Write-Host ''
-    }
-} catch {
-    Write-ColorText '错误: 更新版本号失败' 'Red'
-    Write-ColorText $_.Exception.Message 'Red'
-    exit 1
-}

+ 14 - 0
versions/v1.0.0.md

@@ -0,0 +1,14 @@
+# v1.0.0
+
+初始版本
+
+## 功能
+
+- 变更事件冒泡
+- Rx 响应式流 + 弱引用消息
+- 可插拔调度环境
+- 事件过滤与节流
+- TPL Dataflow 背压管线
+- 批量操作与事件合并
+- 快照导出与导入
+- 线程安全集合节点