我的setup.exe所在的文件夾包含一個子文件夾CAL
,其文件名爲xyz1234.cal
- 它們的名稱因客戶而異。這些文件必須複製到目標目錄中的文件夾CAL
。 所以我創建了一個CustomAction和一個使用File.Copy()
函數的C#dll。我的C#函數接收字符串srcDir
和destDir
作爲參數,例如D:\installation\CAL
和C:\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
讓我們的節目片段,您可以設置自定義操作的屬性(也從您的自定義操作的提取物可以幫助)。這可能是您爲自定義操作設置的屬性錯誤或(可能)您使用File.Copy()的方式() –
這很奇怪。在初始化之後寫入'srcDir'來記錄文件,只是爲了確保。 – Dialecticus
@Dialecticus:當我登錄'srcDir'時,我得到'D:\ installation \ CAL'。當我登錄'Path.GetFullPath(srcDir)'我得到'C:\ Windows \ Installer \ MSID839.tmp- \ D:\ installation \ CAL' –