Sample C# Custom Action

Deployment Tools Foundation

Deployment Tools Foundation Sample C# Custom Action

MSI custom actions are MUCH easier to write in C# than in C++!

    [CustomAction]
    public static ActionResult SampleCustomAction1(Session session)
    {
        session.Log("Hello from SampleCA1");
        
        string testProp = session["SampleCATest"];
        string testProp2;
        testProp2 = (string) session.Database.ExecuteScalar(
            "SELECT `Value` FROM `Property` WHERE `Property` = 'SampleCATest'");
        
        if(testProp == testProp2)
        {
            session.Log("Simple property test passed.");
            return ActionResult.Success;
        }
        else
            return ActionResult.Failure;
    }
            

A sample CA project with two CAs is included in the Samples\ManagedCA directory.  Running the CustomActionTest project will package the CA and insert it into a test MSI. The MSI will invoke the custom actions, but it will not install anything since the second sample CA returns ActionResult.UserExit.


See also: