【发布时间】:2014-10-15 20:35:44
【问题描述】:
我想在调用 setup.exe 时将参数传递给 msi,如下所示:
setup.exe /l* log.txt EXEPATH="C:\Program Files (x86)\MySetup\MyApplication.exe"
我有以下 msbuild 文件:
<Project ToolsVersion="4.0"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<exeD Condition="'$(EXEPATH)'!=''">$(EXEPATH.substring(0,$([MSBuild]::Add($(EXEPATH.lastIndexOf("\")),1))))</exeD>
<exeFile Condition="'$(EXEPATH)'!=''">$(EXEPATH.substring($([MSBuild]::Add($(EXEPATH.lastIndexOf("\")),1))))</exeFile>
</PropertyGroup>
<ItemGroup>
<BootstrapperFile Include="Microsoft.Windows.Installer.4.5" >
<ProductName>Windows Installer 4.5</ProductName>
</BootstrapperFile>
</ItemGroup>
<Target Name="Bootstrapper">
<Message Text="$(exeD)"/>
<Message Text="$(exeFile)"/>
<Message Text="$(EXEPATH)"/>
<Exec Command="msiexec /i MySetup.msi /L log2.txt EXEDIR="$(exeD)" EXEFILENAME="$(exeFile)"" Condition="'$(EXEPATH)'!=''" />
</Target>
</Project>
如您所见,我计算了两个变量 exeFile 和 exeD,我将在 Exec 命令中使用这两个变量,然后将它们传递给 wix 文件所在的 MSI 文件:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="MySetup" Language="1033" Version="1.0.0.0" Manufacturer="Sofiane" UpgradeCode="c151e7ab-b83a-445f-93b2-2ab7122ea34b">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Property Id="EXEDIR" Secure="yes" Value="{}"/>
<Property Id="EXEFILENAME" Secure="yes" Value="{}"/>
<Feature Id="ProductFeature" Title="MySetup" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
<Binary Id="InstallTools" SourceFile="$(var.SolutionDir)InstallTools\bin\$(var.Configuration)\InstallTools.dll"/>
<Binary Id="NotepadPlus" SourceFile="C:\Program Files (x86)\Notepad++\notepad++.exe"/>
<!--<CustomAction Id="OpenExe" BinaryKey="InstallTools" DllEntry="OpenExeUrl" Execute="immediate" Impersonate="yes" Return="check" />-->
<CustomAction Id="OpenExe" Return="ignore" Directory="exeDirectory" ExeCommand=""[EXEDIR]\[EXEFILENAME]"" Impersonate="yes" Execute="deferred"/>
<InstallExecuteSequence>
<Custom Action="OpenExe" Before='InstallFinalize'/>
</InstallExecuteSequence>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="MySetup" />
</Directory>
<Directory Id="exeDirectory" FileSource="@(EXEDIR)" />
</Directory>
</Fragment>
<Fragment>
<DirectoryRef Id="INSTALLFOLDER">
<Component Id="myAppFile">
<File Source="$(var.MyApplication.TargetPath)" />
</Component>
</DirectoryRef>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
<!-- <Component Id="ProductComponent"> -->
<ComponentRef Id="myAppFile" />
<!-- </Component> -->
</ComponentGroup>
</Fragment>
</Wix>
奇怪的是,当我测试使用时,它工作正常,并且打开了exe文件。
MSBuild.exe bootstrapper.msbuild /p:EXEPATH="C:\Program Files (x86)\MySetup\MyApplication.exe"
问题是当我使用以下命令启动 setup.exe 时
setup.exe /l* log.txt EXEPATH="C:\Program Files (x86)\MySetup\MyApplication.exe"
EXEPATH参数好像没用或者不知道为什么?
有什么建议吗?
【问题讨论】:
-
我在您的帖子中没有看到任何问题。尝试查看和编辑,因为如果我不知道您在说什么,我无法回答。
-
亲爱的@jdlugosz 我已经编辑了我的帖子。请检查一下。