fix: 修复 release.bat 路径和版本读取问题

- 使用延迟扩展处理包含括号的路径 (x86)
- 修正版本号解析 token 索引 (tokens=3)
- 移除中文注释避免编码问题

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Administrator
2025-12-18 17:21:04 +08:00
parent 7aa7605ff5
commit bfa2e32b18

View File

@@ -7,19 +7,16 @@ echo PackagingMallShipper - Release Tool
echo ======================================== echo ========================================
echo. echo.
:: 切换到脚本所在目录
cd /d "%~dp0" cd /d "%~dp0"
:: 检查 Inno Setup
set "ISCC=" set "ISCC="
if exist "C:\Program Files (x86)\Inno Setup 6\ISCC.exe" ( set "ISCC_PATH1=C:\Program Files (x86)\Inno Setup 6\ISCC.exe"
set "ISCC=C:\Program Files (x86)\Inno Setup 6\ISCC.exe" set "ISCC_PATH2=C:\Program Files\Inno Setup 6\ISCC.exe"
)
if exist "C:\Program Files\Inno Setup 6\ISCC.exe" (
set "ISCC=C:\Program Files\Inno Setup 6\ISCC.exe"
)
if "%ISCC%"=="" ( if exist "!ISCC_PATH1!" set "ISCC=!ISCC_PATH1!"
if exist "!ISCC_PATH2!" set "ISCC=!ISCC_PATH2!"
if "!ISCC!"=="" (
echo [Error] Inno Setup 6 not found echo [Error] Inno Setup 6 not found
echo. echo.
echo Please download and install Inno Setup 6: echo Please download and install Inno Setup 6:
@@ -29,29 +26,27 @@ if "%ISCC%"=="" (
exit /b 1 exit /b 1
) )
:: 读取当前版本号
set "CURRENT_VERSION=" set "CURRENT_VERSION="
for /f "tokens=2 delims=<>" %%a in ('type "PackagingMallShipper\PackagingMallShipper.csproj" ^| findstr "<Version>"') do ( for /f "tokens=3 delims=<>" %%a in ('type "PackagingMallShipper\PackagingMallShipper.csproj" ^| findstr "<Version>"') do (
set "CURRENT_VERSION=%%a" set "CURRENT_VERSION=%%a"
) )
if "%CURRENT_VERSION%"=="" ( if "!CURRENT_VERSION!"=="" (
echo [Error] Could not read version from csproj file echo [Error] Could not read version from csproj file
echo. echo.
pause pause
exit /b 1 exit /b 1
) )
echo [Info] Current version: %CURRENT_VERSION% echo [Info] Current version: !CURRENT_VERSION!
echo. echo.
:: 询问是否更新版本
if "%1"=="" ( if "%1"=="" (
echo Options: echo Options:
echo 1. Keep current version [%CURRENT_VERSION%] echo 1. Keep current version [!CURRENT_VERSION!]
echo 2. Increment patch version (x.x.X) echo 2. Increment patch version
echo 3. Increment minor version (x.X.0) echo 3. Increment minor version
echo 4. Increment major version (X.0.0) echo 4. Increment major version
echo 5. Enter custom version echo 5. Enter custom version
echo. echo.
set /p "CHOICE=Select option [1-5]: " set /p "CHOICE=Select option [1-5]: "
@@ -60,51 +55,49 @@ if "%1"=="" (
goto :set_version goto :set_version
) )
if "%CHOICE%"=="1" ( if "!CHOICE!"=="1" (
set "NEW_VERSION=%CURRENT_VERSION%" set "NEW_VERSION=!CURRENT_VERSION!"
goto :build goto :build
) )
if "%CHOICE%"=="2" ( if "!CHOICE!"=="2" (
call :increment_patch %CURRENT_VERSION% call :increment_patch !CURRENT_VERSION!
goto :set_version goto :set_version
) )
if "%CHOICE%"=="3" ( if "!CHOICE!"=="3" (
call :increment_minor %CURRENT_VERSION% call :increment_minor !CURRENT_VERSION!
goto :set_version goto :set_version
) )
if "%CHOICE%"=="4" ( if "!CHOICE!"=="4" (
call :increment_major %CURRENT_VERSION% call :increment_major !CURRENT_VERSION!
goto :set_version goto :set_version
) )
if "%CHOICE%"=="5" ( if "!CHOICE!"=="5" (
set /p "NEW_VERSION=Enter new version (e.g. 1.2.3): " set /p "NEW_VERSION=Enter new version: "
goto :set_version goto :set_version
) )
set "NEW_VERSION=%CURRENT_VERSION%" set "NEW_VERSION=!CURRENT_VERSION!"
goto :build goto :build
:set_version :set_version
echo. echo.
echo [Step 1] Updating version to %NEW_VERSION%... echo [Step 1] Updating version to !NEW_VERSION!...
:: 更新 csproj 文件中的版本号 powershell -Command "(Get-Content 'PackagingMallShipper\PackagingMallShipper.csproj') -replace '<Version>[0-9]+\.[0-9]+\.[0-9]+</Version>', '<Version>!NEW_VERSION!</Version>' -replace '<FileVersion>[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+</FileVersion>', '<FileVersion>!NEW_VERSION!.0</FileVersion>' -replace '<AssemblyVersion>[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+</AssemblyVersion>', '<AssemblyVersion>!NEW_VERSION!.0</AssemblyVersion>' | Set-Content 'PackagingMallShipper\PackagingMallShipper.csproj' -Encoding UTF8"
powershell -Command "(Get-Content 'PackagingMallShipper\PackagingMallShipper.csproj') -replace '<Version>[0-9]+\.[0-9]+\.[0-9]+</Version>', '<Version>%NEW_VERSION%</Version>' -replace '<FileVersion>[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+</FileVersion>', '<FileVersion>%NEW_VERSION%.0</FileVersion>' -replace '<AssemblyVersion>[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+</AssemblyVersion>', '<AssemblyVersion>%NEW_VERSION%.0</AssemblyVersion>' | Set-Content 'PackagingMallShipper\PackagingMallShipper.csproj' -Encoding UTF8"
:: 更新 setup.iss 文件中的版本号 powershell -Command "(Get-Content 'setup.iss') -replace '#define MyAppVersion \"[0-9]+\.[0-9]+\.[0-9]+\"', '#define MyAppVersion \"!NEW_VERSION!\"' | Set-Content 'setup.iss' -Encoding UTF8"
powershell -Command "(Get-Content 'setup.iss') -replace '#define MyAppVersion \"[0-9]+\.[0-9]+\.[0-9]+\"', '#define MyAppVersion \"%NEW_VERSION%\"' | Set-Content 'setup.iss' -Encoding UTF8"
echo [Info] Version updated to %NEW_VERSION% echo [Info] Version updated to !NEW_VERSION!
echo. echo.
:build :build
echo [Step 2] Building Release version... echo [Step 2] Building Release version...
dotnet build -c Release dotnet build -c Release
if %ERRORLEVEL% NEQ 0 ( if !ERRORLEVEL! NEQ 0 (
echo [Error] Build failed! echo [Error] Build failed!
pause pause
exit /b 1 exit /b 1
@@ -133,30 +126,26 @@ echo.
echo [Step 4] Compiling installer... echo [Step 4] Compiling installer...
echo. echo.
"%ISCC%" setup.iss "!ISCC!" setup.iss
if %ERRORLEVEL% EQU 0 ( if !ERRORLEVEL! EQU 0 (
echo. echo.
echo ======================================== echo ========================================
echo [Success] Release completed! echo [Success] Release completed!
echo. echo.
echo Version: %NEW_VERSION% echo Version: !NEW_VERSION!
echo Installer: installer\PackagingMallShipper_Setup_v%NEW_VERSION%.exe echo Installer: installer\PackagingMallShipper_Setup_v!NEW_VERSION!.exe
echo ======================================== echo ========================================
echo. echo.
if exist "installer" explorer "installer" if exist "installer" explorer "installer"
) else ( ) else (
echo. echo.
echo [Error] Installer compilation failed, error code: %ERRORLEVEL% echo [Error] Installer compilation failed
) )
pause pause
exit /b 0 exit /b 0
:: ==========================================
:: Version increment functions
:: ==========================================
:increment_patch :increment_patch
for /f "tokens=1,2,3 delims=." %%a in ("%1") do ( for /f "tokens=1,2,3 delims=." %%a in ("%1") do (
set /a "PATCH=%%c+1" set /a "PATCH=%%c+1"