How do I change ROOTDRIVE with a CustomAction?

2019-04-14 06:58发布

Normally, you can change the default root drive to install your application to using:

<Property Id="ROOTDRIVE">D:\</Property>

But now, I wish to change it using a CustomAction that gets called on a next button click in my install wizard:

[CustomAction]
public static ActionResult SetFullInstallRootDrive(Session session) {
    session["ROOTDRIVE"] = session["DRIVE_NAMES"].ToString();
}

DRIVE_NAMES represents the drive selected, using a combo box, and ROOTDRIVE gets properly set to either whatever local drive I choose (in example, C:\ or D:\). However, the installer always installs to the D:\ drive originally set in the property above. What is going on, and how can I change this property's value on the fly in a custom action so that I can let the user select the root drive to install my web application? The property DOES get set, but it doesn't use it, its almost as if the ROOTDRIVE property only gets evaluated once, at the start of the installation wizard.

2条回答
兄弟一词,经得起流年.
2楼-- · 2019-04-14 07:30

I was able to solve my own problem by modifying the TARGETDIR instead of the ROOTDRIVE:

<InstallExecuteSequence>
  <Custom Action="FormatTargetDirectory" After="CostFinalize">NOT Installed</Custom> 
</InstallExecuteSequence> 

<CustomAction Directory="TARGETDIR" Value="[DRIVE_NAMES]" Id="FormatTargetDirectory"/>`
查看更多
做个烂人
3楼-- · 2019-04-14 07:42

Using 3.5 I have been able to setup an MSI that will install on E: if available, otherwise install on C:. Instead of using VBS or a C# custom action, I simply add three lines to the WIX.

<Property Id="ROOTDRIVE" Value="C:\">
  <DirectorySearch Id="Root_search" Path="E:\" Depth="1">
</Property>

ROOTDRIVE is one of those special, poorly documented WIX properties. Once you know it exists, it's function is pretty obvious. It sets the root drive of the install. Using the DirectorySearch simply looks at the E: drive and if available "overwrites" the initial "C:\" value.

You don't need to change the installation order or create a custom action of any kind.

It is pretty simple and I wanted to share it!

查看更多
登录 后发表回答