WiX:将安装路径传递给托管自定义操作
新的一天,新的问题;-) 仍然需要与托管的自定义操作作斗争。我已经设法让它调用自定义操作并向其传递一些测试数据。现在我想用我需要的真实数据替换测试数据。问题就开始了:我想调用一个安装在我的安装子目录中的批处理文件。因此我需要将安装路径传递给自定义操作。据我所知,这可以使用 customactiondata 机制来完成。但这是行不通的。当我记录安装时,我可以看到在 customaction INSTALLLOCATION 之外指向正确的路径,但是当我查看 customaction 时,customactiondata 属性为空...
我做错了什么?
调用自定义操作的合并模块:
<Module Id="DflHelpInstaller" Language="1033" Version="1.0.0.0">
<Package Id="f952de58-1dc6-46b3-872a-7a49e2d9ea0a" Manufacturer="DflHelpInstaller" InstallerVersion="200" />
<Binary Id='RegisterDflHelpDll' SourceFile="$(var.REGISTERHELP.TargetDir)RegisterDflHelp.CA.dll" />
<CustomAction Id='RegisterDflHelp' BinaryKey='RegisterDflHelpDll' DllEntry='RegisterDflHelp' Execute='deferred' />
<CustomAction Id="RegisterDflHelp.SetProperty" Return="check" Property="RegisterDflHelp" Value='[INSTALLLOCATION]' Execute='immediate' />
<InstallExecuteSequence>
<Custom Action='RegisterDflHelp.SetProperty' After='CostFinalize' />
<Custom Action='RegisterDflHelp' After='InstallFiles' />
</InstallExecuteSequence>
<Directory Id="TARGETDIR" Name="SourceDir">
</Directory>
<ComponentGroupRef Id="HelpGroup"/>
</Module>
</Wix>
使用 MergeModule 的安装程序项目概述:
....
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder" SourceName="PFFiles">
<Directory Id="Company" Name='$(var.COMPANY)'>
<Directory Id="INSTALLLOCATION" SourceName='$var.v[SDK_VERSION]'>
<Component Id="MyBanner" Guid="C8C28B92-9326-4991-BFB1-BBDFDF3653AB">
<File Id ="Banner.bmp" Source="Banner.bmp" KeyPath="yes" DiskId="1"/>
</Component>
<Merge Id ="DflHelpInstaller" SourceFile="DflHelpInstaller.msm" Language="1033" DiskId="1" />
</Directory>
</Directory>
....
<Feature Id="Complete" Title="Setup" Description="Installs the SDK on your local machine." Display="expand" Level="1" ConfigurableDirectory="INSTALLLOCATION">
<ComponentRef Id="Banner" />
<ComponentRef Id ="UNINSTALLER"/>
<ComponentGroupRef Id="ReferenceGroup"/>
<MergeRef Id="DflHelpInstaller"/>
</Feature>
CustomAction:
public class CustomActions
{
[CustomAction]
public static ActionResult RegisterDflHelp(Session session)
{
session.Log("Begin CustomAction1");
session.Log("Before Access to customactiondata");
//should contain the installation path - unfortunately it is empty! why?
string cad = session["CustomActionData"];
Debugger.Break();
RegisterHelp(cad);
session.Log("End of custom action..");
return ActionResult.Success;
}
new Day, new Problem;-) Still got to struggle with managed custom action. I already managed it to call an custom action and passing some test data to it. Now I want to replace the testdata with the real data i need. And here the problems starts: I want to call a batch file which was installed in a subdirectory of my installation. Therefore i need to pass the installation path to the custom action. Afaik this can be done using the customactiondata mechanism. But this does not work. When I log the installation I can see that outside of the customaction INSTALLLOCATION is pointing to the correct path, but as soon as i look in the customaction the customactiondata property is empty...
What am I doing wrong?
Merge Module which calls the custom action:
<Module Id="DflHelpInstaller" Language="1033" Version="1.0.0.0">
<Package Id="f952de58-1dc6-46b3-872a-7a49e2d9ea0a" Manufacturer="DflHelpInstaller" InstallerVersion="200" />
<Binary Id='RegisterDflHelpDll' SourceFile="$(var.REGISTERHELP.TargetDir)RegisterDflHelp.CA.dll" />
<CustomAction Id='RegisterDflHelp' BinaryKey='RegisterDflHelpDll' DllEntry='RegisterDflHelp' Execute='deferred' />
<CustomAction Id="RegisterDflHelp.SetProperty" Return="check" Property="RegisterDflHelp" Value='[INSTALLLOCATION]' Execute='immediate' />
<InstallExecuteSequence>
<Custom Action='RegisterDflHelp.SetProperty' After='CostFinalize' />
<Custom Action='RegisterDflHelp' After='InstallFiles' />
</InstallExecuteSequence>
<Directory Id="TARGETDIR" Name="SourceDir">
</Directory>
<ComponentGroupRef Id="HelpGroup"/>
</Module>
</Wix>
Outline of the installer Project which use the MergeModule:
....
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder" SourceName="PFFiles">
<Directory Id="Company" Name='$(var.COMPANY)'>
<Directory Id="INSTALLLOCATION" SourceName='$var.v[SDK_VERSION]'>
<Component Id="MyBanner" Guid="C8C28B92-9326-4991-BFB1-BBDFDF3653AB">
<File Id ="Banner.bmp" Source="Banner.bmp" KeyPath="yes" DiskId="1"/>
</Component>
<Merge Id ="DflHelpInstaller" SourceFile="DflHelpInstaller.msm" Language="1033" DiskId="1" />
</Directory>
</Directory>
....
<Feature Id="Complete" Title="Setup" Description="Installs the SDK on your local machine." Display="expand" Level="1" ConfigurableDirectory="INSTALLLOCATION">
<ComponentRef Id="Banner" />
<ComponentRef Id ="UNINSTALLER"/>
<ComponentGroupRef Id="ReferenceGroup"/>
<MergeRef Id="DflHelpInstaller"/>
</Feature>
CustomAction:
public class CustomActions
{
[CustomAction]
public static ActionResult RegisterDflHelp(Session session)
{
session.Log("Begin CustomAction1");
session.Log("Before Access to customactiondata");
//should contain the installation path - unfortunately it is empty! why?
string cad = session["CustomActionData"];
Debugger.Break();
RegisterHelp(cad);
session.Log("End of custom action..");
return ActionResult.Success;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
如果您将数据描述为...
您可以像这样访问数据:
在前面的示例中,您将使用:
然后
If you delineate your data like ...
You can access the data like:
In the previous example you would use:
then
我在 .WXS 文件中使用以下内容完成了此操作:
在自定义操作中:
现在,我还没有弄清楚如何避免文件名重复,但这确实成功返回了批处理文件的安装位置。
I accomplished this using the following in the .WXS file:
And in the custom Action:
Now, I haven't yet figured out how to avoid the duplication of the filename, but this does successfully return where the batch file was installed.
经过几个小时的努力,以下内容对我有用:
希望它对其他人有帮助!
After several hours of struglling, the following worked for me:
Hope it helps somenone else!
您正确传递了值,但尝试用这种方式引用它。
这应该将
cad
设置为您想要的安装路径。Your passing the value correctly but try this way to reference it.
This should set
cad
to the installation path like you want it.您是否尝试过直接从托管 CA 中查询 INSTALLLOCATION 属性?
使用 DTF 的优点之一是您可以读/写访问所有 MSI 属性,而无需使用命令行等。因此,即使无法像普通属性一样查询 INSTALLLOCATION,您也可以定义自己的 MSI 属性,将其设置为INSTALLOCATION 的值并在您的 CA 内查询该值。
Have you tried querying the INSTALLLOCATION property directly from within the managed CA?
One of the beauties of using DTF is that you have read/write access to all the MSI properties without having to use command-lines etc. So even if INSTALLLOCATION cannot be queried like a normal property you could define your own MSI property set it to the value of INSTALLOCATION and query that one inside your CA instead.
为了向 Session 对象添加新属性:
以安装目录路径为例:
只需添加一个新的 CustomAction 类型属性:
并添加一个新的 InstallExecuteSequence
然后在代码中您可以像这样访问这个新属性:
In order to add a new property to the Session object :
with the installation directory path for example :
Just add a new CustomAction of type property :
And add a new InstallExecuteSequence
Then in the code you access this new property like this :
WixSharp 的示例:
Example for WixSharp: