WIX 安装程序:确保构建时的连续版本号
WIX Installer: ensure successive Version numbers on build
我正在尝试使用我的 Visual Studio 构建自动化我的 Wix 安装程序构建。我正在 installer.wicproj:
中通过此获取应用程序的应用程序版本
<Target Name="BeforeBuild">
<!-- Get Assembly Version -->
<!-- Update built assembly below-->
<GetAssemblyIdentity AssemblyFiles="..\DavesDonutsInstallerTest\bin\Debug\DavesDonuts.exe">
<Output TaskParameter="Assemblies" ItemName="AssemblyVersion"/>
</GetAssemblyIdentity>
<PropertyGroup>
<DefineConstants>BuildVersion=%(AssemblyVersion.Version)</DefineConstants>
</PropertyGroup>
</Target>
然后我在我的主 Product.wxs 中使用它来填充版本号:
<Product Id="*"
Name="!(loc.ProductName)"
Language="1033"
Version="$(var.BuildVersion)"
Manufacturer="!(loc.Developer)"
UpgradeCode="{40CB43C5-1910-4B9D-ABD2-92F620E7125C}">
这很好用。但是,它的意思是,如果我在不增加主项目属性中的应用程序版本的情况下构建安装程序,则安装程序可以正常构建。但是,如果我 运行 在开发机器上运行此程序,安装程序将再次 运行s 并且我会在卸载工具中获得该应用程序的两个条目(本质上是同一应用程序的两个或多个安装。
我不想每次都手动更新 Product ID
,因此自动生成。
我想要一个系统,其中 Wix 安装程序构建器检测到它正在使用与上次相同的版本号进行构建,它停止构建并在输出中发出警告 window。
我想象这将在 install.wixproj BeforeBuild
函数中完成,但不知道如何实现它。我想它是这样工作的。构建成功后,构建版本将写入 WixINstaller 项目文件夹中的文本文件(通过 AfterBuild
??)。然后在下一个 BeforeBuild
上检索并与 'present' 应用程序版本进行比较,如果它们匹配,则停止构建并抛出错误。
Brownie points:一些例程来确定它是否是较低的构建版本,以控制在设置应用程序版本时的错误。
Wix 看起来很强大,但有点莫名其妙。
我确实通过 Pre-Build VS 中的构建事件完全在 WIX 之外管理了这个。只需将此批处理脚本放入您的 Pre-Build 框中即可。还管理了额外检查比上一个版本号更低的布朗尼点。它还在 VS 的错误面板中发布错误和警告。
或者
::Error Thrown by Build Script
@echo off
setlocal ENABLEDELAYEDEXPANSION
:: SETTINGS VARS
:: exceptionOnMatchingVersion can be Warning, Error or None. Be careful of trailing spaces
set exceptionOnMatchingVersion=Error
echo ==========================
echo PRE-BUILD EVENTS
echo ==========================
echo Build Type: $(ConfigurationName)
echo Project: $(ProjectName)
echo.
echo Checking Build Assembly Version for Wix Installer Build
:: PROCESS VARS
set /p lastversion=<lastbuildversion.txt
set version=0.0.0.0
FOR /F delims^=^"^ tokens^=2 %%i in ('findstr /b /c:"[assembly: AssemblyVersion(" $(ProjectDir)\Properties\AssemblyInfo.cs') do (
set version=%%i
)
set concatVersion=0.0.0
set /a presentMajor=0
set /a presentMinor=0
set /a presentPatch=0
set /a lastMajor=0
set /a lastMinor=0
set /a lastPatch=0
for /F "tokens=1,2,3 delims=." %%a in ("%version%") do (
set concatVersion=%%a.%%b.%%c
set /a presentMajor=%%a
set /a presentMinor=%%b
set /a presentPatch=%%c
)
for /F "tokens=1,2,3 delims=." %%a in ("%lastversion%") do (
set /a lastMajor=%%a
set /a lastMinor=%%b
set /a lastPatch=%%c
)
echo Build Full Assembly Version: %version%
echo Concatinated Assembly Version: %concatVersion%
echo Last Concatinated Assembly Version: %lastversion%
set lowerVersion=False
If "$(ConfigurationName)"=="Release" (
If "%lastversion%" == "%concatVersion%" (
If NOT %exceptionOnMatchingVersion% == None (
echo.
echo ======================================================================================================================================================
echo = ALERT: The last Assembly Version is the same as this Build's Assembly Version. This causes issues with the installer. Please ammend the version number.
echo = *** YOU ARE ADVISED NOT TO DEPLOY THIS VERSION ***
echo ======================================================================================================================================================
echo.
If %exceptionOnMatchingVersion% == Warning (
echo Warning: The last Assembly Version is the same as this Build's Assembly Version. This causes issues with the installer. Please ammend the version number.
)
If %exceptionOnMatchingVersion% == Error (
echo Error: The last Assembly Version is the same as this Build's Assembly Version. This causes issues with the installer. Please ammend the version number. BUILD STOPPED.
exit 1
)
)
) else (
if %presentPatch% LSS %lastPatch% (
if %presentMinor% LEQ %lastMinor% (
set "lowerVersion=True"
)
) else (
if %presentMinor% LSS %lastMinor% (
if %presentMajor% LEQ %lastMajor% (
set "lowerVersion=True"
)
) else (
if %presentMajor% LSS %lastMajor% (
set "lowerVersion=True"
)
)
)
if "!lowerVersion!"=="True" (
echo.
echo ======================================================================================================================================================
echo = FATAL EXCEPTION: You are trying to build the assembly to a lower version numer. Please check your numbering. BUILD STOPPED..
echo = *** YOU ARE ADVISED NOT TO DEPLOY THIS VERSION ***
echo ======================================================================================================================================================
echo.
echo Error: You are trying to build the assembly to a lower version numer. Please check your numbering. BUILD STOPPED. This version: %concatVersion%. Last Version: %lastversion%
exit 1
) else (
echo ======================================================================================================================================================
echo = VERSION NUMBER VALID: Proceeding to build. \o/
echo ======================================================================================================================================================
)
)
)
:: echo Lower Version: %lowerVersion%
echo %concatVersion%> lastbuildversion.txt
我正在尝试使用我的 Visual Studio 构建自动化我的 Wix 安装程序构建。我正在 installer.wicproj:
中通过此获取应用程序的应用程序版本 <Target Name="BeforeBuild">
<!-- Get Assembly Version -->
<!-- Update built assembly below-->
<GetAssemblyIdentity AssemblyFiles="..\DavesDonutsInstallerTest\bin\Debug\DavesDonuts.exe">
<Output TaskParameter="Assemblies" ItemName="AssemblyVersion"/>
</GetAssemblyIdentity>
<PropertyGroup>
<DefineConstants>BuildVersion=%(AssemblyVersion.Version)</DefineConstants>
</PropertyGroup>
</Target>
然后我在我的主 Product.wxs 中使用它来填充版本号:
<Product Id="*"
Name="!(loc.ProductName)"
Language="1033"
Version="$(var.BuildVersion)"
Manufacturer="!(loc.Developer)"
UpgradeCode="{40CB43C5-1910-4B9D-ABD2-92F620E7125C}">
这很好用。但是,它的意思是,如果我在不增加主项目属性中的应用程序版本的情况下构建安装程序,则安装程序可以正常构建。但是,如果我 运行 在开发机器上运行此程序,安装程序将再次 运行s 并且我会在卸载工具中获得该应用程序的两个条目(本质上是同一应用程序的两个或多个安装。
我不想每次都手动更新 Product ID
,因此自动生成。
我想要一个系统,其中 Wix 安装程序构建器检测到它正在使用与上次相同的版本号进行构建,它停止构建并在输出中发出警告 window。
我想象这将在 install.wixproj BeforeBuild
函数中完成,但不知道如何实现它。我想它是这样工作的。构建成功后,构建版本将写入 WixINstaller 项目文件夹中的文本文件(通过 AfterBuild
??)。然后在下一个 BeforeBuild
上检索并与 'present' 应用程序版本进行比较,如果它们匹配,则停止构建并抛出错误。
Brownie points:一些例程来确定它是否是较低的构建版本,以控制在设置应用程序版本时的错误。
Wix 看起来很强大,但有点莫名其妙。
我确实通过 Pre-Build VS 中的构建事件完全在 WIX 之外管理了这个。只需将此批处理脚本放入您的 Pre-Build 框中即可。还管理了额外检查比上一个版本号更低的布朗尼点。它还在 VS 的错误面板中发布错误和警告。
或者
::Error Thrown by Build Script
@echo off
setlocal ENABLEDELAYEDEXPANSION
:: SETTINGS VARS
:: exceptionOnMatchingVersion can be Warning, Error or None. Be careful of trailing spaces
set exceptionOnMatchingVersion=Error
echo ==========================
echo PRE-BUILD EVENTS
echo ==========================
echo Build Type: $(ConfigurationName)
echo Project: $(ProjectName)
echo.
echo Checking Build Assembly Version for Wix Installer Build
:: PROCESS VARS
set /p lastversion=<lastbuildversion.txt
set version=0.0.0.0
FOR /F delims^=^"^ tokens^=2 %%i in ('findstr /b /c:"[assembly: AssemblyVersion(" $(ProjectDir)\Properties\AssemblyInfo.cs') do (
set version=%%i
)
set concatVersion=0.0.0
set /a presentMajor=0
set /a presentMinor=0
set /a presentPatch=0
set /a lastMajor=0
set /a lastMinor=0
set /a lastPatch=0
for /F "tokens=1,2,3 delims=." %%a in ("%version%") do (
set concatVersion=%%a.%%b.%%c
set /a presentMajor=%%a
set /a presentMinor=%%b
set /a presentPatch=%%c
)
for /F "tokens=1,2,3 delims=." %%a in ("%lastversion%") do (
set /a lastMajor=%%a
set /a lastMinor=%%b
set /a lastPatch=%%c
)
echo Build Full Assembly Version: %version%
echo Concatinated Assembly Version: %concatVersion%
echo Last Concatinated Assembly Version: %lastversion%
set lowerVersion=False
If "$(ConfigurationName)"=="Release" (
If "%lastversion%" == "%concatVersion%" (
If NOT %exceptionOnMatchingVersion% == None (
echo.
echo ======================================================================================================================================================
echo = ALERT: The last Assembly Version is the same as this Build's Assembly Version. This causes issues with the installer. Please ammend the version number.
echo = *** YOU ARE ADVISED NOT TO DEPLOY THIS VERSION ***
echo ======================================================================================================================================================
echo.
If %exceptionOnMatchingVersion% == Warning (
echo Warning: The last Assembly Version is the same as this Build's Assembly Version. This causes issues with the installer. Please ammend the version number.
)
If %exceptionOnMatchingVersion% == Error (
echo Error: The last Assembly Version is the same as this Build's Assembly Version. This causes issues with the installer. Please ammend the version number. BUILD STOPPED.
exit 1
)
)
) else (
if %presentPatch% LSS %lastPatch% (
if %presentMinor% LEQ %lastMinor% (
set "lowerVersion=True"
)
) else (
if %presentMinor% LSS %lastMinor% (
if %presentMajor% LEQ %lastMajor% (
set "lowerVersion=True"
)
) else (
if %presentMajor% LSS %lastMajor% (
set "lowerVersion=True"
)
)
)
if "!lowerVersion!"=="True" (
echo.
echo ======================================================================================================================================================
echo = FATAL EXCEPTION: You are trying to build the assembly to a lower version numer. Please check your numbering. BUILD STOPPED..
echo = *** YOU ARE ADVISED NOT TO DEPLOY THIS VERSION ***
echo ======================================================================================================================================================
echo.
echo Error: You are trying to build the assembly to a lower version numer. Please check your numbering. BUILD STOPPED. This version: %concatVersion%. Last Version: %lastversion%
exit 1
) else (
echo ======================================================================================================================================================
echo = VERSION NUMBER VALID: Proceeding to build. \o/
echo ======================================================================================================================================================
)
)
)
:: echo Lower Version: %lowerVersion%
echo %concatVersion%> lastbuildversion.txt