I have an MSI installer with a c# custom action running at the end that executes an sql script before the installer exits. We decided the best way to do this is to stick the sql script file in the same directory as the MSI file and have it load the script that way.
The problem is, the installer copies itself to Windows\system32 and then executes from there, so I cannot find the original directory in order to execute the script file. Any help or ideas would be 开发者_运维百科appreciated!
Does OriginalDatabase
property help you?
The Windows Installer sets the OriginalDatabase property to the path of the installation database used to launch the installation. If the installation is launched from a command line, the value depends on whether the recache package option (the -v flag) is present in the REINSTALLMODE property.
If you are writing managed custom actions in C# you should be using Windows Installer XML's (WiX) Deployment Tools Foundation (DTF). You can create a C# project and add your SQL file as project content and it will get packaged up along for the ride and be available in the current directory at runtime.
BTW, assuming ( or not ) that you are using MSSQL, WiX already has SQL script execution handling.
精彩评论