如何通过';会议';将InstallShield用于我的WiX自定义操作的参数?
我有简单的WiX(Microsoft.Deployment.WindowsInstaller)自定义操作:如何通过';会议';将InstallShield用于我的WiX自定义操作的参数?,wix,installshield,custom-action,Wix,Installshield,Custom Action,我有简单的WiX(Microsoft.Deployment.WindowsInstaller)自定义操作: [CustomAction] public static ActionResult TestDtf(Session session) { MessageBox.Show("Test"); ActionResult result = ActionResult.Success; return result; }
[CustomAction]
public static ActionResult TestDtf(Session session)
{
MessageBox.Show("Test");
ActionResult result = ActionResult.Success;
return result;
}
public static int MakeChangesInCurrentInstallSession(Session hMsi)
我需要一个使用InstallShield创建的延迟/系统上下文自定义操作来调用它,那么如何设置方法签名参数,以便它发送会话?“会话”基本上是Msi句柄吗?我已尝试使用“MsiHandle”值,但这会导致错误:
InstallShield: Deferred action requested property MsiHiddenProperties not provided by CustomActionData
InstallShield: Loading assembly Test.Installation.CustomActions from resource 4098
InstallShield: Loading Assembly Microsoft.Deployment.WindowsInstaller
InstallShield: Unexpected parameter type Microsoft.Deployment.WindowsInstaller.Session encountered; passing string instead
InstallShield: Calling method with parameters [(System.String)294]
InstallShield: Exception: System.ArgumentException: Object of type 'System.String' cannot be converted to type 'Microsoft.Deployment.WindowsInstaller.Session'.
at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at InstallShield.ClrHelper.CustomActionHelper.CallMethod(EntryPointInfo info)
你不需要,你不需要。您在InstallShield中创建了错误类型的自定义操作。假设您的DLL不是.NET,因为就DTF而言,它不是。它已被封装为本机DLL。对我来说,这个问题的答案是更改添加到MSI DLL的DLL CA的类型。然后它只要求函数名,而不要求参数和返回值。不幸的是,我在网上找不到现成的解释,这需要一些猜测。下面是您的方法签名的外观
[CustomAction]
public static ActionResult VerifyCA( Session session )
{
//Record record = new Record( 2 );
//record[0] = "[1]";
//record[1] = "Testing Wix message";
//session.Message( InstallMessage.Error, record );
return ActionResult.Failure;
}
在选择了正确的CA类型后,它对我来说就像Installshield 2009的魅力一样。希望这对其他人有所帮助。我的答案是w.r.t.Installshiled 2016,很可能它在早期installshield版本中也会以同样的方式工作,但我还没有验证过这一点 对。内置的
MsiHandle
变量是正在进行的安装的会话,但它需要一行额外的代码才能在C端完成。我能够在从托管自定义操作调用的.NET程序集中实现它。代码如下:
//import this namespace at the top of your *.cs file
using Microsoft.Deployment.WindowsInstaller;
public static int MakeChangesInCurrentInstallSession(IntPtr hMsi)
{
Session session = Session.FromHandle(hMsi, false);
view = session.Database.OpenView("SELECT * FROM ComboBox");
view.Execute();
//do other things whatever you want to do in the installer session
//Record record = session.Database.CreateRecord(4);
//view.Modify(....);
//.....
//return success if everything went well
return (int)ActionResult.Success;
}
如果您对方法进行如下签名,并试图从托管自定义操作调用它:
[CustomAction]
public static ActionResult TestDtf(Session session)
{
MessageBox.Show("Test");
ActionResult result = ActionResult.Success;
return result;
}
public static int MakeChangesInCurrentInstallSession(Session hMsi)
然后,您将面临以下铸造错误:
//import this namespace at the top of your *.cs file
using Microsoft.Deployment.WindowsInstaller;
public static int MakeChangesInCurrentInstallSession(IntPtr hMsi)
{
Session session = Session.FromHandle(hMsi, false);
view = session.Database.OpenView("SELECT * FROM ComboBox");
view.Execute();
//do other things whatever you want to do in the installer session
//Record record = session.Database.CreateRecord(4);
//view.Modify(....);
//.....
//return success if everything went well
return (int)ActionResult.Success;
}
InstallShield:意外的参数类型
遇到Microsoft.Deployment.WindowsInstaller.Session;经过
而不是字符串
注意:要使上述代码正常工作,您必须在“添加引用”窗口的“扩展”选项卡中的C#项目中添加对Microsoft.Deployment.WindowsInstaller.dll的引用。此外,由于此程序集不是.NET framework的一部分,因此您必须将此程序集作为依赖项添加到Installshield执行序列的托管自定义操作中,详细说明如下。DTF在我的博客上有详细说明。