Improve publish script with dynamic versioning

Added dynamic version resolution from the `<Version>` tag in the
`.csproj` file, enabling versioned output directories. Updated
`setlocal` to use `enabledelayedexpansion` for better variable
handling. Enhanced logging of build parameters and streamlined
the "Publishing" step by removing redundant logs.

Improved output verification with additional checks for critical
files (`hostfxr.dll`, `coreclr.dll`, etc.), logging failures if
files are missing. Updated success messages to include the
resolved version and generalized next-step instructions.
This commit is contained in:
2026-09-21 14:17:49 +02:00
parent 310d2efc6e
commit 01cd8b2607

View File

@@ -1,5 +1,5 @@
@echo off
setlocal
setlocal enabledelayedexpansion
echo ============================================================
echo EnvelopeGenerator.Server - Self-Contained Publish
@@ -10,11 +10,38 @@ echo.
REM Must be run from the solution root directory.
REM This file is located under: EnvelopeGenerator.Server\
set PROJECT=EnvelopeGenerator.Server\EnvelopeGenerator.Server.csproj
set OUTPUT=publish-output
set PROJECT=%~dp0EnvelopeGenerator.Server\EnvelopeGenerator.Server.csproj
set RID=win-x64
set FRAMEWORK=net8.0
REM ── Resolve project version from .csproj ──────────────────────────────────────
REM Reads the <Version> element directly from the .csproj XML using findstr.
REM Example: <Version>1.1.0-beta</Version> → VERSION=1.1.0-beta
REM 'tokens=2 delims=>' splits on '>' and takes the second token (the value+tag),
REM then 'delims=<' strips the closing '<' tag leaving the bare version string.
for /f "tokens=2 delims=>< " %%v in ('findstr /i "<Version>" "%PROJECT%"') do (
set VERSION=%%v
)
if "%VERSION%"=="" (
echo [ERROR] Could not read ^<Version^> from %PROJECT%. Aborting.
pause
exit /b 1
)
REM ── Output path: network share / versioned subfolder ──────────────────────────
REM Format: M:\App&Service\0 DD - Smart UP\signFLOW\Server\net8\{version}
REM Note: the '&' in the path is literal — no escaping needed inside a set "..." assignment.
set "OUTPUT=M:\App&Service\0 DD - Smart UP\signFLOW\Server\net8\%VERSION%"
echo [0/3] Resolved build parameters
echo Project : %PROJECT%
echo Version : %VERSION%
echo Output : %OUTPUT%
echo RID : %RID%
echo Framework: %FRAMEWORK%
echo.
echo [1/3] Cleaning previous publish output...
if exist "%OUTPUT%" (
rmdir /s /q "%OUTPUT%"
@@ -25,10 +52,6 @@ if exist "%OUTPUT%" (
echo.
echo [2/3] Publishing...
echo Project : %PROJECT%
echo Output : %OUTPUT%
echo RID : %RID%
echo Framework: %FRAMEWORK%
echo.
dotnet publish "%PROJECT%" ^
@@ -50,36 +73,37 @@ echo [3/3] Verifying output...
set PASS=1
if not exist "%OUTPUT%\EnvelopeGenerator.Server.exe" (
if not exist "!OUTPUT!\EnvelopeGenerator.Server.exe" (
echo [FAIL] EnvelopeGenerator.Server.exe not found!
set PASS=0
)
if not exist "%OUTPUT%\hostfxr.dll" (
) else ( echo [OK] EnvelopeGenerator.Server.exe )
if not exist "!OUTPUT!\hostfxr.dll" (
echo [FAIL] hostfxr.dll not found! (Not a self-contained publish?)
set PASS=0
)
if not exist "%OUTPUT%\coreclr.dll" (
) else ( echo [OK] hostfxr.dll )
if not exist "!OUTPUT!\coreclr.dll" (
echo [FAIL] coreclr.dll not found! (Not a self-contained publish?)
set PASS=0
)
if not exist "%OUTPUT%\Microsoft.Extensions.DependencyInjection.Abstractions.dll" (
) else ( echo [OK] coreclr.dll )
if not exist "!OUTPUT!\Microsoft.Extensions.DependencyInjection.Abstractions.dll" (
echo [FAIL] Microsoft.Extensions.DependencyInjection.Abstractions.dll not found!
set PASS=0
)
if not exist "%OUTPUT%\web.config" (
) else ( echo [OK] Microsoft.Extensions.DependencyInjection.Abstractions.dll )
if not exist "!OUTPUT!\web.config" (
echo [FAIL] web.config not found!
set PASS=0
)
) else ( echo [OK] web.config )
if "%PASS%"=="1" (
if "!PASS!"=="1" (
echo.
echo ============================================================
echo PUBLISH SUCCEEDED
echo Output folder: %~dp0%OUTPUT%
echo Version : !VERSION!
echo Output folder: !OUTPUT!
echo ============================================================
echo.
echo Next steps:
echo 1. Copy the contents of '%OUTPUT%' to the IIS application directory
echo 1. Copy the contents of the output folder to the IIS application directory
echo 2. Set the IIS Application Pool to 'No Managed Code'
echo 3. Recycle the Application Pool
echo.