I have already created custom action project to copy files from source directory to installation directory. but it's causing problem when I repair application. I am not getting [SOURCEDIR] variable that I have set from CustomActionData.
/TARGETDIR="[TARGETDIR]\" /SOURCEDIR="[SOURCEDIR]\ "
Here is the code.
Code:using System; using System.Collections; using System.Collections.Generic; using System.ComponentModel; using System.Configuration.Install; using System.Linq; using System.Windows.Forms; namespace CustomInstallerProject { [RunInstaller(true)] public partial class CopyFileInstaller : Installer { public CopyFileInstaller() { InitializeComponent(); } public override void Install(IDictionary stateSaver) { base.Install(stateSaver); string targetDir = this.Context.Parameters["TARGETDIR"].Trim(); string sourceDir =this.Context.Parameters["SOURCEDIR"].Trim(); string dbFile = "xyz.mdf"; string dbFileLog = "xyz_log.ldf"; string addressFile = "add.dll"; bool succeeded = true; if (succeeded) CopyFile(sourceDir, targetDir + @"Data\", dbFile, false, "[ErrorCode: 11] Database file is missing. Please contact your vender.", "[ErrorCode: 12] Unexpected error occured while creating database. Please contact your vender."); if (succeeded) CopyFile(sourceDir, targetDir + @"Data\", dbFileLog, false, "[ErrorCode: 21] Database file is missing. Please contact your vender.", "[ErrorCode: 22] Unexpected error occured while creating database. Please contact your vender."); if (succeeded) CopyFile(sourceDir, targetDir, addressFile, true, "[ErrorCode: 31] Address file is missing. Please contact your vender.", "[ErrorCode: 32] Unexpected error occured while copying address file. Please contact your vender."); } private bool CopyFile(string sourceDir, string targetDir, string fileName, bool overwrite, string fileMissingMessage, string unexpectedErrorMessage) { bool result = true; try { if (!System.IO.File.Exists(sourceDir + fileName)) { result = false; throw new InstallException(fileMissingMessage); } else { bool copyFile = true; if (System.IO.File.Exists(targetDir + fileName) && !overwrite) { copyFile = false; } if (copyFile) { System.IO.File.Copy(sourceDir + fileName, targetDir + fileName, overwrite); } } } catch (Exception ex) { result = false; MessageBox.Show(sourceDir); throw new InstallException(unexpectedErrorMessage); } return result; } } }




Reply With Quote