安装程序 – WiX:将安装路径传递到托管自定义操作

前端之家收集整理的这篇文章主要介绍了安装程序 – WiX:将安装路径传递到托管自定义操作前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
新的一天,新的问题;-)仍然需要与自定义的行动斗争.我已经管理它来调用自定义操作并将一些测试数据传递给它.现在我想用我需要的真实数据替换testdata.这里的问题开始:我想调用一个批处理文件,它被安装在我的安装的子目录中.因此,我需要将安装路径传递给自定义操作. Afaik这可以使用customactiondata机制来完成.但这不行.当我记录安装时,我可以看到,在定制操作INSTALLLOCATION之外指向正确的路径,但是一旦我查看customaction,customactiondata属性是空的…

任何人都可以看看我的代码,并给我一个提示我做错了什么?感谢你的好意!

调用自定义操作的合并模块:

  1. <Module Id="DflHelpInstaller" Language="1033" Version="1.0.0.0">
  2. <Package Id="f952de58-1dc6-46b3-872a-7a49e2d9ea0a" Manufacturer="DflHelpInstaller" InstallerVersion="200" />
  3.  
  4. <Binary Id='RegisterDflHelpDll' SourceFile="$(var.REGISTERHELP.TargetDir)RegisterDflHelp.CA.dll" />
  5.  
  6. <CustomAction Id='RegisterDflHelp' BinaryKey='RegisterDflHelpDll' DllEntry='RegisterDflHelp' Execute='deferred' />
  7.  
  8. <CustomAction Id="RegisterDflHelp.SetProperty" Return="check" Property="RegisterDflHelp" Value='[INSTALLLOCATION]' Execute='immediate' />
  9.  
  10.  
  11. <InstallExecuteSequence>
  12. <Custom Action='RegisterDflHelp.SetProperty' After='CostFinalize' />
  13. <Custom Action='RegisterDflHelp' After='InstallFiles' />
  14. </InstallExecuteSequence>
  15.  
  16. <Directory Id="TARGETDIR" Name="SourceDir">
  17. </Directory>
  18. <ComponentGroupRef Id="HelpGroup"/>
  19.  
  20. </Module>
  21. </Wix>

使用MergeModule的安装程序的大纲:

….

  1. <Directory Id="TARGETDIR" Name="SourceDir">
  2. <Directory Id="ProgramFilesFolder" SourceName="PFFiles">
  3. <Directory Id="Company" Name='$(var.COMPANY)'>
  4. <Directory Id="INSTALLLOCATION" SourceName='$var.v[SDK_VERSION]'>
  5. <Component Id="MyBanner" Guid="C8C28B92-9326-4991-BFB1-BBDFDF3653AB">
  6. <File Id ="Banner.bmp" Source="Banner.bmp" KeyPath="yes" DiskId="1"/>
  7. </Component>
  8. <Merge Id ="DflHelpInstaller" SourceFile="DflHelpInstaller.msm" Language="1033" DiskId="1" />
  9. </Directory>
  10. </Directory>

….

  1. <Feature Id="Complete" Title="Setup" Description="Installs the SDK on your local machine." Display="expand" Level="1" ConfigurableDirectory="INSTALLLOCATION">
  2. <ComponentRef Id="Banner" />
  3. <ComponentRef Id ="UNINSTALLER"/>
  4. <ComponentGroupRef Id="ReferenceGroup"/>
  5. <MergeRef Id="DflHelpInstaller"/>
  6. </Feature>

CustomAction:

  1. public class CustomActions
  2. {
  3. [CustomAction]
  4. public static ActionResult RegisterDflHelp(Session session)
  5. {
  6. session.Log("Begin CustomAction1");
  7. session.Log("Before Access to customactiondata");
  8.  
  9. //should contain the installation path - unfortunatelly it is empty! why?
  10. string cad = session["CustomActionData"];
  11. Debugger.Break();
  12.  
  13.  
  14. RegisterHelp(cad);
  15.  
  16. session.Log("End of custom action..");
  17. return ActionResult.Success;
  18. }
如果你描述你的数据…
  1. <CustomAction Id="MyCustomActionData" Return="check" Property="MyCustomAction" Value='PROPERTY0=[PROPERTY0];PROPERTY1=[PROPERTY1];PROPERTY2=[PROPERTY2]' Execute='immediate' />

您可以访问以下数据:

  1. string property0 = session.CustomActionData["Property0"];
  2. string property1 = session.CustomActionData["Property1"];
  3. string property2 = session.CustomActionData["Property2"];

在上一个例子中,您将使用:

  1. <CustomAction Id="RegisterDflHelp.SetProperty" Return="check" Property="RegisterDflHelp" Value='INSTALLLOCATION=[INSTALLLOCATION]' Execute='immediate' />

然后

  1. string cad = session.CustomActionData["INSTALLLOCATION"];

猜你在找的Windows相关文章