2015-06-09 60 views
0

我的setup.exe所在的文件夾包含一個子文件夾CAL,其文件名爲xyz1234.cal - 它們的名稱因客戶而異。這些文件必須複製到目標目錄中的文件夾CAL。 所以我創建了一個CustomAction和一個使用File.Copy()函數的C#dll。我的C#函數接收字符串srcDirdestDir作爲參數,例如D:\installation\CALC:\MyApp\CAL。 然而,當我檢查文件夾是否存在與Directory.Exists(srcDir),一個異常被拋出,雖然目錄D:\installation\CAL存在:WiX - 複製任意文件

ERROR in custom action myFunction System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Windows\Installer\MSID839.tmp-\D:\installation\CAL'.

這種情況無論CustomAcion是否立即執行或延遲。 C:\Windows\Installer\MSID839.tmp-\似乎是執行程序集的路徑,但我當然不希望將其作爲FullPath的一部分。我怎樣才能擺脫它?

CustomAction和屬性的定義,像這樣: <CustomAction Id='myCA' BinaryKey='myCABin' DllEntry='myFunction' Execute="deferred" HideTarget="no" Impersonate="no"/> <Property Id="myCA" Value="Arg1=[CURRENTDIRECTORY];Arg2=[INSTALLDIR]" />

的參數用於像這樣:

CustomActionData data = session.CustomActionData; 
string srcDir = data["Arg1"]+ "\\CAL"; 
string destDir = data["Arg2"]+ "\\CAL"; 
if (Directory.Exists(srcDir)) 
    // copy files 
+0

讓我們的節目片段,您可以設置自定義操作的屬性(也從您的自定義操作的提取物可以幫助)。這可能是您爲自定義操作設置的屬性錯誤或(可能)您使用File.Copy()的方式() –

+0

這很奇怪。在初始化之後寫入'srcDir'來記錄文件,只是爲了確保。 – Dialecticus

+0

@Dialecticus:當我登錄'srcDir'時,我得到'D:\ installation \ CAL'。當我登錄'Path.GetFullPath(srcDir)'我得到'C:\ Windows \ Installer \ MSID839.tmp- \ D:\ installation \ CAL' –

回答

0

我重新創建你的應用程序,它工作正常。這裏是我的WiX的代碼(這是我的產品節點內):

<CustomAction Id='Test' BinaryKey='RegistryHelperCA' DllEntry='Test' Execute="deferred" HideTarget="no" Impersonate="no"/> 
<Property Id="Test" Value="Arg1=[CURRENTDIRECTORY];Arg2=[INSTALLDIR]" /> 

<InstallExecuteSequence> 
    <Custom Action="Test" After="InstallFiles"></Custom> 
</InstallExecuteSequence> 

我的自定義操作:

[CustomAction("Test")] 
    public static ActionResult Test(Session session) 
    { 
     string dir = session.CustomActionData["Arg1"]; 
     session.Log("DIRECTORY equals " + dir); 

     if (Directory.Exists(dir)) 
      session.Log("Success"); 

     return ActionResult.Success; 
    } 

它吐出來的目錄爲C:\Users\user\Desktop。驗證你是不是分配給你的CURRENTDIRECTORY財產的任何地方,如果你沒有找到任何東西,試試你的自定義操作設置爲Execute="immediate"和訪問這樣

string srcDir = session["CURRENTDIRECTORY"]+ "\\CAL";

的數據。如果不工作,當然,該屬性被覆蓋的地方。祝你好運!

+0

是的,我認爲你是在正確的軌道上,屬性是覆蓋,因爲如果我傳遞硬編碼的字符串作爲參數,一切都很好。現在的問題是:如何轉換或包裝屬性的原始內容,以便只傳遞期望的路徑? –

+1

@ Germany'snextDilbert我不確定你在問什麼。在我看來,你應該做的是搜索'CURRENTDIRECTORY'的所有實例,找到它被覆蓋的地方並修復代碼。如果這不是你要問的,你能否詳細說明一下? – sirdank

+0

您的提示立即執行幫助 - 謝謝。 –

0

一些嘗試和錯誤的會話後,我發現,Directory.Exists(srcDir)Directory.Exists(destDir)沒有工作,因爲沒有價值,但屬性名作爲參數傳遞給Exist()功能 - 對比session.Log(srcDir)其正確的產生值。

最後,我結束了與設置execute="immediate"和檢索像這樣的價值觀:

srcDir = session["CURRENTDIRECTORY"]; 
destDir = session.GetTargetPath("INSTALLDIR");