21

在旧版 Visual Studio 部署项目安装程序中,传递指定值的命令行参数TARGETDIR允许我覆盖默认安装位置(我的大部分安装都在没有用户交互的情况下进行,因此大量使用命令行自动化)。但是,我得到的印象是 WiX(默认情况下)TARGETDIR用于不同的东西。虽然我可以(并且将)更新我们的命令行工具来更改参数名称,但仍然需要手动修改我们现有的所有安装(一项非同寻常的工作)。

有没有办法通过指定TARGETDIR而不破坏任何东西来覆盖 WiX 包中的安装位置?

4

1 回答 1

28

After doing more digging, it looks like my previous experience is a result of behavior specific to VSDPROJ's (and possibly InstallShield), wheras WiX is conforming to the Windows Installer.

As I discovered at this link, TARGETDIR is actually supposed to represent the root of the drive with the most free space available (assuming there's more than one). That's why WiX projects have directories nested under there for Program Files, etc. Visual Studio actually adds a custom action that overrides this property to the full installation path.

I was able to accomplish what I wanted by doing two things:

  1. Change all of my components and component groups to install to TARGETDIR instead of INSTALLFOLDER (the default directory that WiX put in there)
  2. Add a custom action that sets the value of the TARGETDIR property to the installation path, assuming one wasn't passed in from the command line.

To do that, I added this under the <Product> tag:

<CustomAction Id="SetTARGETDIR" Property="TARGETDIR" 
              Value="[ProgramFilesFolder][Manufacturer]\[ProductName]" 
              Execute="firstSequence" />

And this within the <InstallExecuteSequence> tag:

<Custom Action="SetTARGETDIR" Before="CostFinalize">TARGETDIR=""</Custom>
于 2012-06-12T19:52:33.157 回答