In a standard Setup project for a WinForms app I would like to programmatically change the default installation folder (i.e. do this when the installation happens).
Is there a way to do this? I thought using a custom Installer class might hep me with this but it seems by the time it gets to any custom actions in that class, the install folder has already been selected.
I had the same problem. Here Is my solution. I created an additional project, which called Win msi intaller, and add the TARGETDIR property's value as an argument.
static void Main()
{
Process setupProcess = new Process();
string msiFilePath = @"c:\path to msi package";
string targetDir = @"target dir path";
setupProcess.StartInfo.FileName = @"msiexec.exe /i " + msiFilePath + " TARGETDIR=\"" + targetDir + "\"";
setupProcess.StartInfo.UseShellExecute = false;
setupProcess.Start();
}
Then you should run this program to install your msi package.