如何编写一个WiX自定义操作
我有这个托管自定义操作代码。不知道如何在我的Wix脚本中编写它的调用。应该在InstallFinalize之后排定自定义操作吗?它能被调度为OnExit=“错误”吗?
[CustomAction]
public static void CopyLogFile(Session session)
{
const string company = "MyCompany";
const string product = "MyProduct";
try
{
session.Log("CustomAction.CopyLogFile entry");
var msiLogFilePath = session.CustomActionData["LOGFILEPATH"];
if (msiLogFilePath != null)
{
session.Log("CustomAction.CopyLogFile MSI log filename: {0}", msiLogFilePath);
var localAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
var destDirPath = Path.Combine(localAppDataPath, company, product);
var destDir = Directory.CreateDirectory(destDirPath);
session.Log("CustomAction.CopyLogFile Destination directory: {0}", destDir.FullName);
var destFilePath = Path.Combine(destDir.FullName, Path.GetFileName(msiLogFilePath));
File.Copy(msiLogFilePath, destFilePath, true);
session.Log("CustomAction.CopyLogFile Log file copied to: {0}", destFilePath);
}
else
{
session.Log("CustomAction.CopyLogFile File path not found");
}
}
catch (Exception exception)
{
session.Log("CustomAction.CopyLogFile exception {0}", exception);
}
finally
{
if (session != null)
{
session.Log("CustomAction.CopyLogFile exit");
session.Close();
}
}
}发布于 2014-03-26 13:32:22
是的,您可以在InstallFinalize之后安排它(我也是,但是如果它不是完全删除包的话,我每次都会复制它):
<InstallExecuteSequence>
<Custom Action="CopyLogfile" After="InstallFinalize">NOT (REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE)</Custom>
</InstallExecuteSequence>请记住,如果有,也要将其添加到UI序列中。我把它作为事件添加到PushButton中的SetupCompleteSuccess中-和SetupCompleteError-dialogs (也许您只需要将它添加到后一个?)如下所示:
<Dialog Id="SetupCompleteSuccess" X="50" Y="50" Width="374" Height="266" Title="[ProductName]" NoMinimize="yes">
<Control Id="OK" Type="PushButton" X="230" Y="243" Width="66" Height="17" Text="&Finish" TabSkip="no" Default="yes" Cancel="yes">
<Publish Event="EndDialog" Value="Exit">1</Publish>
<!-- ### Invoking copying the logfile if the Finish-button is pressed -->
<Publish Event="DoAction" Value="CopyLogfile">MsiLogFileLocation AND NOT (REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE)</Publish>
</Control>
<!-- ... rest of the dialog ... -->
</Dialog>关于只在错误情况下显示它:可能检查ProductState-properrty?在网上搜索这个,但没有发现任何有用的东西。
编辑:也许只有在发生错误时才执行它的正确方法是使用Custom标志,这些标志只在回滚期间执行。在WiX中,它将是CustomAction-tag的Execute="rollback"-attribute。
发布于 2014-03-26 15:05:46
如果你能帮忙的话,不要在InstallFinalize之后处理自定义操作。它们通常在通过SCCM、Unicenter等工具部署时被完全跳过.
但是,在安装结束时使用一个按钮打开日志文件的自定义对话框可以正常工作。
https://stackoverflow.com/questions/22650003
复制相似问题