我在安装新版本之前正在执行主要升级和卸载现有产品。但我想保留现有的配置文件。
由于早期版本没有使用Permanent =“yes”,因此在卸载时会删除配置文件。
我怎样才能做这样的事情,在卸载前将'app.config'复制为'app.config.bak'。卸载后将其从“app.config.bak”恢复为“app.config”。
<DirectoryRef Id="INSTALLDIR">
<Component Id="BackupConfigComponent" Guid="87368AF7-4BA2-4302-891A-B163ADDB7E9C">
<CopyFile Id="BackupConfigFile" SourceDirectory="INSTALLFOLDER" SourceName="app.config" DestinationDirectory="INSTALLFOLDER" DestinationName="app.config.bak" />
</Component>
</DirectoryRef>
<DirectoryRef Id="INSTALLDIR">
<Component Id="RestoreConfigComponent" Guid="87368AF7-4BA2-4302-891A-B163ADDB7E9C">
<CopyFile Id="RestoreConfigFile" SourceDirectory="INSTALLFOLDER" SourceName="app.config.bak" DestinationDirectory="INSTALLFOLDER" DestinationName="app.config" />
</Component>
</DirectoryRef>
<InstallExecuteSequence>
<Custom Action="BackupConfigFile" After="InstallInitialize" />
<RemoveExistingProducts After="InstallInitialize" />
<Custom Action="RestoreConfigFile" After="InstallInitialize" />
</InstallExecuteSequence>
由于
答案 0 :(得分:3)
您所要做的就是将<Custom Action="RestoreConfigFile" After="InstallInitialize" />
更改为<Custom Action="RestoreConfigFile" After="RemoveExistingProducts " />
这只是一个时间问题。您告诉我们在InstallInitialize之后执行所有三个操作,因此它们很可能不会按照它们的编写顺序保留。明确列出您希望它们的顺序始终是一个更好的主意。更好,更完整的修复方法是:
<Custom Action="BackupConfigFile" After="InstallInitialize" />
<RemoveExistingProducts After="BackupConfigFile" />
<Custom Action="RestoreConfigFile" After="RemoveExistingProducts " />
编辑:(根据评论) 要在MSI中创建自定义操作,您需要创建CustomAction元素。还需要用于创建自定义操作的代码。但是,如果您只是尝试复制文件,我建议您使用CopyFile元素。它比通过所有自定义操作步骤更容易和更清晰,以完成我认为您的目标。