2012-08-05 92 views
0

我想在安装过程中有条件地设置文件扩展名。据我所知,为了在Wix中有条件地做任何事情,它应该是一个独立的组件。因此,对于每个文件类型关联,我想允许用户设置,我有一个组件类似以下内容:如何使用Wix有条件地设置文件扩展名?

<Component Id="FileAssocComponent_PS" Guid="DAFE9461-2DF0-934A-F204-6B28CEA23C01"> 
    <Condition>FILE_ASSOC_PS</Condition> 
    <RegistryValue Root="HKLM" Key="SOFTWARE\PrinterApp\Capabilities\FileAssociations" Name=".prn" Value="PrinterApp.ps" Type="string" /> 
    <RegistryValue Root="HKLM" Key="SOFTWARE\PrinterApp\Capabilities\MIMEAssociations" Name="application/postscript" Value="PrinterApp.ps" Type="string" /> 
    <RegistryValue Root="HKLM" Key="SOFTWARE\Classes\PrinterApp.ps" Name="FriendlyTypeName" Value="PostScript File" Type="string" /> 
    <ProgId Id="PrinterApp.ps" Description="PostScript File" Icon="PrinterApp.ico" Advertise="yes"> 
    <Extension Id="ps"> 
     <Verb Id="open" Command="Open" Argument="&quot;%1&quot;"/> 
    </Extension> 
    </ProgId> 
</Component> 

但是这给了我以下错误:

error LGHT0204: ICE19: Extension: 'ps' advertises component: 'FileAssocComponent_PS'. This component cannot be advertised because the KeyPath type disallows it.

我已经尝试在其中一个注册表项上设置KeyPath =“yes”,但这不起作用 - 并且从我已经能够找到它期望的文件KeyPath。但是这是一个不包含任何文件的组件!

我该如何解决这个错误,或者我会以这种错误的方式解决问题?

回答

3

广告组件需要密钥文件,所以这里有一些解决错误的方法。

1)

给该组件一个假文件(printermimeinstalled.txt),不会损害系统。

2)

作者PrinterAppMime.ps作为此组件的密钥文件。使用CopyFile元素将文件复制到PrinterApp.ps

作者PrinterAppNoMime.ps(相同内容)与另一个组件的密钥文件相同。还可以使用CopyFile元素将文件复制到PrinterApp.ps。给这个组件一个互斥的组件条件,以便只有一个组件获得instaleld。

3)

稍微改变你的应用程序的设计。始终安装PrinterApp.ps,并有条件安装PrinterAppMimeServer.ps。

4)

消除这种自定义操作,并使用自定义操作在installtime创作MSI临时表中的行如果选中该复选框,defind的MIME东西。

这四种方法中的每一种都有专业人员和监护人,我个人会选择#3。

0

如果您设置了Advertise="no"您应该可以使用您编写的代码。下面是几年前我发布的一个示例here,它使用可选文件关联的单独组件。

<Component ....> 
    <ProgId Id="AcmeFoobar.Document" hDescription="ACME XYZ Document"> 
     <Extension Id="pdf" ContentType="application/xyz"> 
      <Verb Id="open" Command="Open" TargetFile="[APPLICATIONFOLDER]AcmeFoobar.exe" Argument="%1" /> 
     </Extension> 
    </ProgId> 

    <Condition><![CDATA[DEFAULTVIEWER=1]]></Condition> 
</Component> 
0

我找到了适合我的解决方案。我遇到的问题是我对扩展名与exe的关联有一个条件。如果扩展未选中不关联,我需要安装exe组件,但没有progid。问题是,如果在组件上放置一个条件,progid将不会被创建,但exe也没有被安装。我找到的解决方案是两个创建两个组件。一个与条件和一个相互排斥的条件。这基本上是Christopher Painters职位的选项2。

见下文:

<Component Id="My.exe" Guid="{D9CF6FDD-1234-4E90-85A1-3BF1F912C1E3}"> 
    <Condition>NOT FILES_ASSOCIATIONS_ABC</Condition> 
    <File Id="My.exe.without_assoc" Name="My.exe" KeyPath="yes" Vital="yes" Compressed="yes" DiskId="1" Source=".\SourceDir\My.exe" /> 
    </Component> 
    <Component Id="My.exe_assoc" Guid="{07F96643-5D74-1234-9DAE-CDEB5AC2D11E}"> 
    <File Id="My.exe.with_assoc" Name="My.exe" KeyPath="yes" Vital="yes" Compressed="yes" DiskId="1" Source=".\SourceDir\My.exe" /> 
    <Condition>FILES_ASSOCIATIONS_ABC</Condition> 
    <ProgId Id="My.Document" Description="My exe" Icon="MyIcon" Advertise="yes"> 
     <Extension Id="abc"> 
     <Verb Id="open" Command="My Exe" Argument="&quot;%1&quot;" /> 
     <MIME Advertise="yes" ContentType="application/abc" Default="yes" /> 
     </Extension> 
    </ProgId> 
    </Component>