MsiSetProperty from C# custom action

浪子不回头ぞ 提交于 2019-12-10 17:56:35

问题


action1How do I set a MSI property from within a C# custom action, so far I have this but how do I get the handle?

[DllImport("msi.dll", CharSet = CharSet.Unicode)]
static extern int MsiSetProperty(IntPtr hInstall, string szName, string szValue);

public void SetProperty(string propertyName, string propertyValue)
{
    MsiSetProperty(handle, propertyName, propertyValue);
}

I am calling the CA from WiX with the following line

<CustomAction Id="CA1" BinaryKey="ca1.dll" DllEntry="action1" />

and the action1 looks like this

public class CustomActions
{
    [CustomAction]
    public static ActionResult action1(Session session)
    {
        session.Log("Begin action1");
        SetProperty("xyz", "123");
    }
} 

回答1:


You should be able to set a property by doing the following:

public class CustomActions 
{ 
    [CustomAction] 
    public static ActionResult action1(Session session) 
    { 
        string xyzProperty = "XYZ";

        session[xyzProperty] = "ABC";
    } 
} 

See Christopher Painter's post here:

http://blog.deploymentengineering.com/2008/05/deployment-tools-foundation-dtf-custom.html

I'm sure he'll be along soon to comment on this one.



来源:https://stackoverflow.com/questions/3307499/msisetproperty-from-c-sharp-custom-action

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!