How can I rollback or cancel an MSI project in C#?
I am trying to build an MSI project, and during installation I am installing a Windows Service. If that service fails to be installed, I want to initiate rollback and cancel the installation.
I have already built an installer class and overridden t开发者_JS百科he install and uninstall method. How can I initiate rollback?
First you should know that using InstallUtil custom actions ( regardless of how documented and written about they are ) are not a good choice. Throw them away. The same goes for the Visual Studio Deployment Project that you are using to consuem your custom action.
The best solution lies in leveraging Windows Installer built-in support for creating and starting services. Use InstallShield 2010 Limited Edition ( Free ) or Windows Installer XML ( FOSS ). These tools expose the ServiceControl table which has a Wait column that allows you to teach MSI:
Wait
Leaving this field null or entering a value of 1 causes the installer to wait a maximum of 30 seconds for the service to complete before proceeding. The wait can be used to allow additional time for a critical event to return a failure error. A value of 0 in this field means to wait only until the service control manager (SCM) reports that this service is in a pending state before continuing with the installation.
ServiceControl Table
精彩评论