我一直在嘗試使用msiexec實現msi安裝並將自定義參數傳遞給它。Wix安裝程序在第一次運行後失敗的自定義操作
msiexec /i somefile.msi /l*v output.txt IPADDRESS="127.0.0.1" PORT="9999"
現在我有下面的代碼來完成獲取IPADDRESS和PORT並將它們寫入文件的工作。下面是我的代碼:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Deployment.WindowsInstaller;
namespace SetupCA
{
public class CustomActions
{
[CustomAction]
public static ActionResult WriteFileToDisk(Session session)
{
session.Log("Begin WriteFileToDisk");
string ipAddress = session["IPADDRESS"];
string port = session["PORT"];
string temp = @"
{{
""ip"" : ""{0}"" ,
""port"" : ""{1}""
}}";
string config = string.Format(temp, ipAddress, port);
session.Log("Config Generated was " + config);
System.IO.Directory.CreateDirectory("C:\\somefolder");
try{
System.IO.File.Delete("C:\\somefolder\\some.config");
}
catch(Exception e){
}
System.IO.File.WriteAllText(@"C:\somefolder\some.config", config);
session.Log("Ending WriteFileToDisk");
return ActionResult.Success;
}
}
}
編輯:全維克斯代碼 我已經使用在維克斯生成的dll文件給出:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="CustomWixInstallerWithCustomAction" Language="1033" Version="1.0.0.0" Manufacturer="Developer" UpgradeCode="ba9015b9-027f-4451-adb2-e38f9168a850">
<Package InstallerVersion="200" Compressed="no" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="CustomWixInstallerWithCustomAction" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="CustomWixInstaller" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<Component Id="SomeRandomEXE">
<File Source ="some.exe" />
</Component>
</ComponentGroup>
<Binary Id="SetupCA" SourceFile="SetupCA.CA.dll"/>
<CustomAction Id="WRITEFILETODISK" Execute="immediate" BinaryKey="SetupCA" DllEntry="WriteFileToDisk" />
<InstallExecuteSequence>
<Custom Action="WRITEFILETODISK" Sequence="2"></Custom>
</InstallExecuteSequence>
</Fragment>
一切工作正常,當我安裝msi使用上面給出的命令。文本文件在參數期間給出的內容的文件夾中生成。但是當我使用相同的命令時,這些參數不會被提取並寫入文件中。但如果我卸載它使用:
msiexec /x file.msi
並再次運行,它的工作原理。這裏有什麼問題?
很抱歉,但對我來說是不明確的,你想什麼。尤其是,對於使用上面給出的命令,「一切正在正常工作......」的意思是......但是當我使用相同的(???)命令時......「。第二:你試圖做什麼,只需將命令行中給出的ip和端口記錄到另一個配置文件中?或者你想從配置文件中取出兩個msi屬性?第三,也是最重要的。 msi日誌文件說什麼,是您的自定義操作是否啓動。沒有這些信息,我們什麼都不會說。 – Philm 2014-11-24 13:09:57
由程序編譯的DLL在Wix中的Custom Action內部使用,它應該獲取給予msifile的參數並在某些配置文件中寫入這些參數。當我使用上面的命令運行msi文件時,它會正確完成所有工作並創建配置文件。當我第二次運行相同的命令等等,這些參數不會被提取,配置文件看起來像{「ip:」「,」port「:」「}。如果我卸載使用下面給出的msifile命令並安裝它我的代碼有問題 – Pant 2014-11-24 14:37:53
@SarvagyaPant你不能反覆執行相同的安裝程序,MSI會檢測到它已經安裝並中止安裝,如果我沒有錯,如果是這種情況,你需要配置你的安裝程序的行爲正確 – Rolo 2014-11-25 01:09:45