2012-08-05 88 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>