2013-08-01 44 views
0

我已閱讀的鏈接後,寫了這個代碼來獲取安裝位置屬性: http://blogs.technet.com/b/alexshev/archive/2008/03/25/property-does-not-exist-or-empty-when-accessed-from-deferred-custom-action.aspx無法在遞延自定義操作

<?xml version="1.0" encoding="UTF-8"?> 
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> 
    <Module Id="MergeModule1" Language="1033" Version="1.0.0.0"> 
    <Package Id="cffa568e-1bf0-4eb3-bee3-eb5801a0bbd0" Manufacturer="Microsoft" InstallerVersion="200" /> 

    <Binary Id="myCustomActionsDLL" SourceFile="CustomAction1.CA.dll" /> 

    <CustomAction Id="SetProperty" Execute="immediate" 
        Property="CA_myCustomAction" 
        Value="InstallDir=[PRIMARYFOLDER];SourceDir=[SourceDir]" /> 


    <CustomAction 
    Id="CA_myCustomAction" 
    BinaryKey="myCustomActionsDLL" 
    DllEntry="CustomAction1" 
    Execute="deferred" Impersonate="no" 
    Return="check" /> 

    <InstallExecuteSequence> 
     <Custom Action="SetProperty" Before="InstallInitialize">Not Installed</Custom> 
     <Custom Action="CA_myCustomAction" Before="InstallFinalize">Not Installed</Custom> 
    </InstallExecuteSequence> 

    <!--<InstallUISequence> 
     <Custom Action="CA_myCustomAction" After="CostFinalize"></Custom> 
    </InstallUISequence>--> 

    </Module> 
</Wix> 

在地方InstallDir - PRIMARYFOLDER,我曾嘗試 - INSTALLLOCATION,INSTALLDIR,TARGETDIR但我我無法獲取爲ProgramFiles(x86)下的應用程序指定的安裝文件夾。

SourceDir的值是在MSI文件運行時找到的正確值。

回答

3

您的故障排除應始終始於生成和讀取詳細日誌。一次可能存在幾個問題,並且都需要同時修復。

首先是您的Type 51設置屬性自定義操作安排在InstallInitialize之前。該屬性不是安全的自定義屬性,因此它不會傳遞到事務中。嘗試在InstallInitialize之後調度它。

其次是你在一個合併模塊和合並模塊modularize(追加GUID)幾乎所有的標識符。如果你看看ORCA中的構建合併模塊,你會發現它不是在尋找INSTALLDIR.GUID的INSTALLDIR。

如果您確實必須使用INSTALLDIR,則您希望定義一個名爲INSTALLDIR且沒有值的屬性,並使用SuppressModularization屬性來防止GUID。我通常採取的方法是定義一個MergeRedirectFolder目錄並使用它。然後,當我將合併模塊添加到InstallShield時,我將該模塊關聯到INSTALLDIR,然後傳遞性自然接管。

可能還有其他問題,但如果不查看最終的MSI並通讀日誌,很難看清楚。

<?xml version="1.0" encoding="UTF-8"?> 
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> 
    <Module Id="MergeModule2" Language="1033" Version="1.0.0.0"> 
    <Package Id="c4acbfbc-a0e8-4d52-b516-bee471a76e8a" Manufacturer="" InstallerVersion="200" /> 
    <Directory Id="TARGETDIR" Name="SourceDir"> 
     <Directory Id="MergeRedirectFolder"/> 
    </Directory> 
    <Binary Id="myCustomActionsDLL" SourceFile="CustomAction1.CA.dll" /> 
    <CustomAction Id="SetProperty" Execute="immediate" 
        Property="CA_myCustomAction" 
        Value="InstallDir=[MergeRedirectFolder];SourceDir=[SourceDir]" /> 
    <CustomAction Id="CA_myCustomAction" 
     BinaryKey="myCustomActionsDLL" 
     DllEntry="CustomAction1" 
     Execute="deferred" Impersonate="no" 
     Return="check" /> 
    <InstallExecuteSequence> 
     <Custom Action="SetProperty" After="InstallInitialize">Not Installed</Custom> 
     <Custom Action="CA_myCustomAction" Before="InstallFinalize">Not Installed</Custom> 
    </InstallExecuteSequence> 

    </Module> 
</Wix> 
+0

非常感謝!似乎沒有人知道除了你以外的其他人。你能給我提供一個例子或指針在互聯網上使用MergeRedirectFolder或SuppressModularization? – teenup

+0

MergeRedirectFolder的更新示例。我不能在這裏顯示的部分是,當您將合併模塊添加到InstallShield時,您必須右鍵單擊它並使用下拉列表將合併模塊與INSTALLDIR關聯。 –

+0

謝謝,我會在星期一嘗試。非常感謝。 – teenup