WiX:如何在托管引导程序中访问/更改安装目录?

5
我正在创建一个带有自定义用户界面的WPF设置应用程序。我从Bryan P. Johnston的教程开始:http://bryanpjohnston.com/2012/09/28/custom-wix-managed-bootstrapper-application/ 在我的视图中,有一个简单的TextBox与我的MainViewModel中的InstallationPath属性绑定。
现在我想要当用户点击“安装”时使用此路径。为此,我有一个按钮绑定到我的InstallCommand。将调用以下方法(直接从教程中提取):
private void InstallExecute()
{
    Bootstrapper.Engine.Plan(LaunchAction.Install);
}

我该如何使安装包安装到我的属性InstallationPath所在的目录中?
编辑:
我在Stackoverflow上找到了一个类似的问题: 在Burn托管的引导程序中指定WiX包的INSTALLLOCATION 那里的答案来自Bob Arnson

使用每个MsiPackage的MsiProperty子项来指定INSTALLLOCATION=[BurnVariable]。然后使用Engine.StringVariables设置BurnVariable。

现在,我认为我可以像这样在我的InstallExecute中访问StringVariables
private void InstallExecute()
{
    Bootstrapper.Engine.StringVariables["BurnVariable"] = InstallationPath;
    Bootstrapper.Engine.Plan(LaunchAction.Install);
}

但是在哪里定义这个变量呢?我猜想应该是在Product.wxs文件中的某个地方。


嗨,Michael,我按照相同的教程进行操作,但在主要升级期间遇到了问题,旧的exe没有被删除,而新的exe是并排安装的。我增加了EXE版本和包含的MSI版本。我看到一些其他人在教程下面评论了相同的问题。你遇到过这个问题吗?如果是,你是如何解决的?:(需要一些帮助) - AnOldSoul
我也使用这个传奇教程,问题是变量不会被覆盖。我的变量返回信息是否安装程序。我可以在C#程序中读取此变量,但无法覆盖它,无论何时尝试都没有改变。Bootstrapper.Engine.StringVariables["SqlStatus"] = "false"; <Variable Name="SsmsStatus" bal:Overridable="yes" Value="true" Type="string"/> 或许有人能帮助我。 - Silny ToJa
3个回答

7

是的,只需在您的burn引导程序中创建一个变量:

<Variable Name="BurnVariable"
          bal:Overridable="yes" />

您可以将此作为参数传递给引导安装的msi包:

<MsiPackage SourceFile="$(var.YourMsiProject.Installer.TargetPath)" Compressed="no">
    <MsiProperty Name="INSTALLLOCATION" Value="[BurnVariable]" />          
</MsiPackage>

1
在Bundle Variable元素上缺少一个属性"Type"。 caverman_dick是正确的,但当不可重写时,这不起作用。 您也可以尝试设置Type="string"。 Wix变量元素
<Wix>...<Bundle>...
  <Variable Name="MyApplicationMsiInstallFolder" Value="[WindowsVolume]MyApplication"
          bal:Overridable="yes" Type="string"/>
    <Chain>
        <?if $(var.DbVersion) = false?>
        <PackageGroupRef Id="AccessDatabaseGroup"/>
        <RollbackBoundary />
        <?endif?>
        <MsiPackage Id="MyApplicationMsiPackage" SourceFile="$(var.MyApplicationSetup.TargetPath)" DisplayInternalUI="no"
                                Vital="yes" >
            <MsiProperty Name="APPLICATIONFOLDER" Value="[MyApplicationMsiInstallFolder]"/>
        </MsiPackage>
    </Chain>
</Bundle></Wix>

0

我也使用这个传奇教程。我想为其他事情使用变量。换句话说,该变量指示程序是否应安装。问题在于,当在InstallExecute()中调用它时,该变量不会被覆盖。对于我的问题,它以这种方式工作:

  protected override void Run()
    {
        this.Engine.Log(LogLevel.Verbose, "Launching custom TestBA UX");
        BootstrapperDispatcher = Dispatcher.CurrentDispatcher;


        MainViewModel viewModel = new MainViewModel(this);
        viewModel.Bootstrapper.Engine.Detect();

        MainView view = new MainView();
        this.Engine.StringVariables["SqlStatus"] = view.CheckInstalledSQL() == true ? "true" : "false";
        this.Engine.StringVariables["SsmsStatus"] = view.CheckInstalledSSMS() == true ? "true" : "false";
        view.DataContext = viewModel;
        view.Closed += (sender, e) => BootstrapperDispatcher.InvokeShutdown();
        view.Show();
        Dispatcher.Run();

        this.Engine.Quit(0);
    }

引导程序:

<Variable Name="SqlStatus" bal:Overridable="yes" Value="false" Type="string"/>
<Variable Name="SsmsStatus" bal:Overridable="yes" Value="false" Type="string"/>
...

<ExePackage Id="SSMS" Name="SQLServerManagementStudio" Cache="no" Compressed="yes" PerMachine="yes" Permanent="yes" Vital="yes"
    InstallCommand="/install /Passive SSMSInstallRoot=C:\\Program Files\\Microsoft SQL Server /norestart"
    SourceFile="C:\Users\..\Downloads\SSMS-Setup-ENU.exe"
    DetectCondition="SsmsStatus = &quot;true&quot;"/>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接