Chr*_*Roy 12 parameters wix build path dynamic
我是一名学生开发人员,我为我现在正在合作的公司建立了几个安装程序.所以我对WIX非常熟悉.我们最近决定使用Build服务器自动构建我们的解决方案.它构建了调试和发布,以及混淆(和非混淆)项目.你真的不需要了解这一点.您需要了解的是,我有相同的Wix项目动态构建不同的MSI.所以我们构建它们的方式是我们用几个参数调用MSBuild.exe.wix项目所依赖的参数.
所以我们假设我们进入命令提示符并写入
C:\>\windows\Microsoft.NET\Framework\v3.5\MSBuild.exe MyApp.Install\MyApp.Install.wixproj /p:Configuration=Release /p:SpecialPath=Obfuscated /t:Build
Run Code Online (Sandbox Code Playgroud)
想法是wix看到"SpecialPath"参数被分配为"混淆"; 并且在安装程序路径中,其源代码
在构建时..\myApp\bin\$(var.SpecialPath)\myApp.exe转换为..\myApp\bin\Obfuscated\myApp.exe.
如何创建这些自定义构建参数并将它们传递给我的.wxs文件.截至目前这个设置,$(var.SpecialPath)没有定义和构建CrashSplosions.
出于明显的法律原因,我不得不削减90%的project.wxs文件并重命名一些东西,但是就所有意图和目的而言,这就是我所拥有的.
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="myApp" Language="1033" Version="$(var.Version)" Manufacturer="myApp" UpgradeCode="$(var.UpgradeCode)">
<Package Id="*" InstallerVersion="200" Compressed="yes" />
<Media Id="1" Cabinet="media.cab" EmbedCab="yes" />
<Directory Id="TARGETDIR" Name="SourceDir" >
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLLOCATION" Name="myApp">
<Component Id="myAppEXE" Guid="FD5EBC02-MY29-GUID-ACCA-61324C5F1B68">
<RegistryKey Root="HKLM" Key="Software\MyApp">
<RegistryValue Value="0" Type="string" KeyPath="yes"/>
</RegistryKey>
<File Id="MYAPPEXE" Name='myApp.exe' Source="..\myApp\bin\$(var.SpecialPath)\myApp.exe" />
</Component>
<Component Id="EngineDLL" Guid="*">
<File Id="ENGINEDLL" Name='Engine.dll' Source="..\myApp\bin\$(var.Configuration)\Engine.dll" />
</Component>
<Component Id="CommonDLL" Guid="*">
<File Id="COMMONDLL" Name='Common.dll' Source="..\myApp\bin\$(var.Configuration)\Common.dll" />
</Component>
</Directory>
</Directory>
</Directory>
<Feature Id="ProductFeature" Title="myApp" Description='All' Display='expand' Level="1" ConfigurableDirectory='INSTALLLOCATION'>
<ComponentRef Id="myAppEXE" />
<ComponentRef Id="EngineDLL" />
<ComponentRef Id="CommonDLL" />
</Feature>
</Product>
</Wix>
Run Code Online (Sandbox Code Playgroud)
Wim*_*nen 17
它不适合您的原因是您在命令行上设置msbuild属性,这些属性不会作为wix变量传递.MSBuild属性和wix变量是两个不同的概念.
解决此问题的一种方法是忽略msbuild属性的概念,并使用环境变量将值直接传递给candle.exe.您可以在wxs文件中使用环境变量,如下所示:
$(env.SpecialPath)
Run Code Online (Sandbox Code Playgroud)
然后,您可以从批处理文件启动安装程序生成,该文件准备必要的环境变量,如下所示:
@echo off
setlocal
set SpecialPath=foo
set Configuration=Release
set msbuild=C:\windows\Microsoft.NET\Framework\v3.5\MSBuild.exe
%msbuild% test.wixproj /t:Build || goto ERROR
exit /b 0
:ERROR
echo Failed to build setup!
exit /b 1
Run Code Online (Sandbox Code Playgroud)
或者,如果您希望通过msbuild属性传递参数,则应首先查看msbuild蜡烛任务文档.它显示您可以在wixproj文件中设置值,如下所示:
<DefineConstants>Variable1=value1;Variable2=value2</DefineConstants>
Run Code Online (Sandbox Code Playgroud)
这仍然需要您在wixproj文件中对值进行硬编码.如果要在命令行上将值作为msbuild属性传递,那么您应该执行以下操作:
<DefineConstants>Variable1=$(value1);Variable2=$(value2)</DefineConstants>
Run Code Online (Sandbox Code Playgroud)
然后传递/p:value1=foo /p:value2=bar命令行,或在其他地方定义这些msbuild属性.
正如已经回答的那样,您需要将变量传递到 WiX 中。我们使用 Nant 而不是 MSBuild,但概念保持不变。
这是一个向蜡烛传递六个变量的 Nant 示例(这不是最干净的示例,而是从我从事的项目中逐字提取的)
<candle out="${dir.obj}\"
rebuild="true"
extensions="WixUIExtension;WixNetFxExtension">
<defines>
<define name="ProcessorArchitecture" value="${release.platform}" />
<define name="SourceDir" value="${dir.source}" />
<define name="version" value="${version}" />
<define name="releasetype" value="${release.type}" />
<define name="Language" value="${language}" />
<define name="product" value="${string.product}" />
<define name="productedition" value="${release.productedition}" />
</defines>
<sources>
<include name="*.wxs" />
<include name="..\Common\*.wxs" />
</sources>
</candle>
<!-- Define fallback culture for non-US -->
<property name="cultures" value="${language}" />
<property name="cultures" value="${language};en-US" unless="${language == 'en-US'}" />
<light
out="${dir.build}\setup_${release.platform}_${release.compressionlevel}.msi"
extensions="WixUIExtension;WixNetFxExtension;WixUtilExtension"
cultures="${cultures}"
rebuild="true"
suppressices="ICE03;ICE82"
suppresspdb="true" >
<arg line="-loc "setup-${language}.wxl"" />
<arg line="-sw1101" />
<arg line="-b ${dir.resources}" />
<arg line="-b ${dir.resources.common}" />
<arg line="-b ${dir.resources.common}\Microsoft" />
<arg line="-b ${dir.source}" />
<arg line="-dcl:${release.compressionlevel}" />
<arg line="-dWixUILicenseRtf=EULA_${language}.rtf" />
<sources>
<include name="${dir.obj}\*.wixobj" />
</sources>
</light>
Run Code Online (Sandbox Code Playgroud)