我是一名学生开发人员,我为我现在正在合作的公司建立了几个安装程序。所以我对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
这个想法是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>
答案 0 :(得分:17)
它不适合您的原因是您在命令行上设置msbuild属性,这些属性不会作为wix变量传递。 MSBuild属性和wix变量是两个不同的概念。
解决此问题的一种方法是忽略msbuild属性的概念,并使用环境变量将值直接传递给candle.exe
。您可以在wxs文件中使用环境变量,如下所示:
$(env.SpecialPath)
然后,您可以从批处理文件启动安装程序生成,该文件准备必要的环境变量,如下所示:
@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
或者,如果您希望通过msbuild属性传递参数,则应首先查看msbuild candle task文档。它显示您可以在wixproj文件中设置值,如下所示:
<DefineConstants>Variable1=value1;Variable2=value2</DefineConstants>
这仍然需要您在wixproj文件中硬编码值。如果要在命令行上将值作为msbuild属性传递,那么您应该执行以下操作:
<DefineConstants>Variable1=$(value1);Variable2=$(value2)</DefineConstants>
然后在命令行上传递/p:value1=foo /p:value2=bar
,或在别处定义这些msbuild属性。
答案 1 :(得分:3)
如前所述,您需要将变量传递给WiX。我们使用Nant而不是MSBuild,但概念保持不变。
这是一个Nant示例,将六个变量传递给candle(这不是最干净的示例,但是从我工作的项目逐字解除)
<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>
答案 2 :(得分:1)
我有类似的情况,文件的源路径作为命令行参数传递给构建脚本。这就是我做的: 编辑了wixproj文件,并在“PropertyGroup”节点下添加了以下内容:
<Source Condition=" '$(Source)' == '' ">R:</Source>
其中R:是从中选择源的默认目录/路径。 现在,源代码也可以在构建期间作为命令行参数传递:
msbuild /t:Clean,Build "MyPath\MyWixProject.wixproj" /property:Source=MyConfigurablePath /p:Configuration=Release