这是我的问题,我需要在安装我的 product.msi 设置时备份文件夹中的现有配置文件。我尝试使用(使用自定义操作)Installer Class
它可以工作,但方向不正确。
只有在整个安装完成后才会进行备份。即,安装后我曾经得到3个配置文件,这3个被作为文件夹中的备份。
我的安装类:
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Install(IDictionary stateSaver)
{
base.Install(stateSaver);
}
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);
string directory = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
String folderPath = directory + "\\Myproduct Before " + version;
string[] newPath = Directory.GetFiles(directory, "*.config");
int newPathCounter = newPath.Count();
if (newPathCounter != 0)
{
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
for (int i = 0; i < newPath.Count(); i++)
{
string source = newPath[i];
string destination = source.Replace(directory, folderPath);
File.Copy(source, destination, true);
}
}
else
{
MessageBox.Show("No files to copy");
}
}
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Rollback(IDictionary savedState)
{
base.Rollback(savedState);
}
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Uninstall(IDictionary savedState)
{
base.Uninstall(savedState);
}
我也尝试过输入这段代码,OnBeforeInstall
但同样的事情发生了。请就此提出建议。