select the folder path and pass to this method.It will create the msi file in the order in which folder hierarchy exists.
public class InstallData
{
public void GetWixData(string SourcePath)
{
try
{
WixEntity[] weDir = new WixEntity[0];
weDir = BuildDirInfo(SourcePath, weDir);
var project = new Project("My Product", new Dir("MyDB", weDir), new ManagedAction("MyAction"))
{
GUID = Guid.NewGuid(),
UI = WUI.WixUI_InstallDir,
Manufacturer = "xxx Inc.",
};
try
{
Compiler.BuildMsi(project, Application.StartupPath);
}
catch (Exception ex)
{
}
}
catch (Exception Ex)
{
}
}
private WixEntity[] BuildDirInfo(string sRootDir, WixEntity[] weDir)
{
DirectoryInfo RootDirInfo = new DirectoryInfo(sRootDir);
if (RootDirInfo.Exists)
{
DirectoryInfo[] DirInfo = RootDirInfo.GetDirectories();
List<string> lMainDirs = new List<string>();
foreach (DirectoryInfo DirInfoSub in DirInfo)
lMainDirs.Add(DirInfoSub.FullName);
int cnt = lMainDirs.Count;
weDir = new WixEntity[cnt + 1];
if (cnt == 0)
weDir[0] = new DirFiles(RootDirInfo.FullName + @"\*.*");
else
{
weDir[cnt] = new DirFiles(RootDirInfo.FullName + @"\*.*");
for (int i = 0; i < cnt; i++)
{
DirectoryInfo RootSubDirInfo = new DirectoryInfo(lMainDirs[i]);
if (!RootSubDirInfo.Exists)
continue;
WixEntity[] weSubDir = new WixEntity[0];
weSubDir = BuildDirInfo(RootSubDirInfo.FullName, weSubDir);
weDir[i] = new Dir(RootSubDirInfo.Name, weSubDir);
}
}
}
return weDir;
}
}
public class CustomActions
{
[CustomAction]
public static ActionResult MyAction(Session session)
{
MessageBox.Show("Hello World!", "Embedded Managed CA");
session.Log("Begin MyAction Hello World");
return ActionResult.Success;
}
}