无法从托管引导程序应用程序 C# 代码中的引导程序变量读取输入 [英] Cannot read input from Bootstrapper variable in Managed Bootstrapper Application C#-Code

查看:29
本文介绍了无法从托管引导程序应用程序 C# 代码中的引导程序变量读取输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已使用托管引导程序应用程序对设置进行了编程.在我的解决方案中有以下项目:- Setup.msi:要安装的 MSI 项目- Setup.UI.dll:安装过程的 WPF-GUI- Bootstrapper.exe:引导程序项目- Launcher.exe:启动引导程序的 WPF 应用程序

I have programmed setup with a managed bootstrapper application. In my solution are the following projects: - Setup.msi : The MSI-project to install - Setup.UI.dll : The WPF-GUI for the installation process - Bootstrapper.exe : The bootstrapper-project - Launcher.exe : A WPF-app to start the bootstrapper

在引导程序包中,我为安装文件夹定义了一个变量:

In the bootstrapper bundle i have defined a variable for the installationfolder:

<Variable Name="INSTALLFOLDER"
          bal:Overridable="yes"
          Type="string"
          Value="[ProgramFilesFolder]"/>

这个变量可以在启动引导程序时由 Launcher 设置:

This variable can be set by the Launcher when starting the bootstrapper:

    Process proc = new Process();
    proc.StartInfo.FileName = "msiexec";
    proc.StartInfo.FileName = "..\\..\\..\\Bootstrapper\\bin\\Debug\\Bootstrapper.exe";
    proc.StartInfo.Arguments = "IsClientSetup=true INSTALLFOLDER=C:\\TestSetup";
    proc.Start();

如果我使用标准引导程序 (WixStandardBootstrapperApplication.RtfLicense),我的给定条目将用于定义的变量 INSTALLFOLDER.我在安装过程中只看到引导程序对话框,但毕竟一切正常.

In case i'm using the standard bootstrapper (WixStandardBootstrapperApplication.RtfLicense) my given entry will be used in the defined variable INSTALLFOLDER. I see only the bootstrapper dialog while the installation process, but after all everythings fine.

但是当我使用托管引导程序(它启动我的 WPF-GUI)并尝试读取安装路径时,我总是从定义中获得默认值:程序文件文件夹.

But when i use the managed bootstrapper, which starts my WPF-GUI, and i try to read the installationpath, i always get the default from the definition: the programfilesfolder.

这里是包中的代码:

<WixVariable Id="WixMbaPrereqPackageId"
             Value="Netfx4Full" />
<WixVariable Id="WixMbaPrereqLicenseUrl"
             Value="NetfxLicense.rtf" />
<BootstrapperApplicationRef Id="ManagedBootstrapperApplicationHost" >
    <Payload Name='BootstrapperCore.config' SourceFile='..\..\..\Setup.UI\bin\Debug\BootstrapperCore.config' />
    <Payload SourceFile='..\..\..\Setup.UI\bin\Debug\SetupUI.dll' />
</BootstrapperApplicationRef>

<Chain>
    <MsiPackage Id="SetupPackage"
                SourceFile="..\..\..\Setup.Msi\bin\Debug\Setup.msi"
                Cache="yes"
                DisplayInternalUI="no"
                Vital="yes"
                Compressed="no"
                EnableFeatureSelection="no"
                DisplayName="SetupForTest">
        <MsiProperty Name="INSTALLLOCATION"
                     Value="[INSTALLFOLDER]" />
</Chain>

以及来自 SetupUI 中的 ViewModel 的代码:

And the code from the ViewModel in SetupUI:

string installationPath = UI.Model.Bootstrapper.Engine.FormatString(UI.Model.Bootstrapper.Engine.StringVariables["INSTALLFOLDER"]);

而且 - 至少 - SetupUI 中的 Run 方法:

And - at least - the Run-method in the SetupUI:

protected override void Run()
{
    MessageBox.Show("1 = " + this.Engine.FormatString(this.Engine.StringVariables["INSTALLFOLDER"]));
    Model = new Model(this);
    Model.Bootstrapper.Engine.Detect();
    MessageBox.Show("2 = " + Model.Bootstrapper.Engine.FormatString(Model.Bootstrapper.Engine.StringVariables["INSTALLFOLDER"]));

    RootViewViewModel viewModel = new RootViewViewModel();
    View = new RootView(viewModel);

    // Populate the view models with data then run the view..
    viewModel.Refresh();
    View.Run();

    this.Engine.Quit(0);
}

谁能告诉我,我做错了什么?

Can anybody tell me, what i have made wrong?

推荐答案

我自己找到了!代码是正确的,但在使用托管引导程序时,变量不会被覆盖.所以我们必须在 SetupUI 中从 BootstrapperApplication 的 CommandLineArguments 中读取它们并将它们设置在变量中.仅此而已.

I've found it myself! The code is correct, but when using a mannaged bootstrapper, the variables are not overwritten. So we have to read them in the SetupUI from the CommandLineArguments of the BootstrapperApplication and set them in the variable. That's all.

这篇关于无法从托管引导程序应用程序 C# 代码中的引导程序变量读取输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆