9

在安装新版本之前,我正在执行重大升级并卸载现有产品。但我想保留现有的配置文件。

由于早期版本没有 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>

谢谢

4

1 回答 1

4

您所要做的就是更改<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元素。这比完成所有自定义操作步骤来做我认为你想做的事情要容易和干净得多。

于 2013-06-21T11:22:15.937 回答