向 app.config 添加了新的应用程序设置,但 MSI 不会安装它(不会覆盖) [英] Added new application setting to app.config but MSI won't install it (doesn't overwrite)

查看:29
本文介绍了向 app.config 添加了新的应用程序设置,但 MSI 不会安装它(不会覆盖)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们最近在旧版 winforms 应用程序 (.Net 4.6.1) 的 app.config(日志服务器的 URL)中添加了一个新的应用程序设置(不是用户设置).

We recently added a new application setting (not user setting) to the app.config (URL to a logging server) of our legacy winforms application (.Net 4.6.1).

旧版本是 1.0.3,我们将所有程序集的版本更改为 1.0.4,并且在安装项目(Visual Studio 2017 安装程序项目)中将版本更改为匹配,从而放弃了更改产品代码的弹出窗口,我们做到了.

Old version was 1.0.3, we changed the version of all assemblies to 1.0.4 and in the Setup project (Visual Studio 2017 Installer Project) changed the version to match which gave up the pop-up to change the product code, which we did.

安装运行正常(顺便说一下,其他东西也发生了变化,这些变化在新版本中是正确的),但我们的新 app.config 设置不是.奇怪的是,如果您手动删除配置文件并重新运行该应用程序,它会重新创建导致新设置出现的配置文件.知道这里发生了什么吗?

The install runs correctly (other things were changed too by the way, and those changes are correctly in the new version), but our new app.config setting is not. Curiously, if you manually delete the config file and re-run the app, it re-creates the config file which causes the new setting to appear. Any idea what's happening here?

谢谢!

推荐答案

您可能没有使用 WiX,但我会添加我在注意到您没有将 WiX 添加为标签之前写的内容.必须学会阅读.

You might not be using WiX, but I'll just add what I wrote before I noticed that you didn't add WiX as a tag. Got to learn to read.

这可能是 MSI/WiX 部署中最常见的问题,以及在主要升级期间删除的配置设置.我假设您已在安装期间将 app.config 文件设置为永久文件以在主要升级期间保留它?

This might be the most common problem of all for MSI / WiX deployment, along with wiped out config settings during major upgrade. I assume you have set the app.config file permanent during installation to preserve it during major upgrade?

可能发生的情况是您已将配置文件安装为文件,但它应该安装为一组 XML 配置设置,这些设置可以合并到目标文件中.

What is likely happening is that you have installed the config file as a file, but it should be installed as a bunch of XML configuration settings that can be merged into the destination file instead.

MSI 文件版本控制规则 尝试保留安装后修改过的非版本控制文件.因此,如果升级时文件的创建和修改日期不同,则不会覆盖非版本化文件.如果没有最新的所需值,您的文件将保持原样.它已被保存".

The MSI file versioning rules attempt to preserve non-versioned files that have been modified after installation. Accordingly a non-versioned file will not be overwritten if the create and modify dates of the file are different on upgrades. Your file will appear untouched without the most recent, desired values. It has been "preserved".

您可以使用适当的 WiX XML 元素更新您的 WiX 源以设置所需的值.有两个不同的元素是相关的:

You can update your WiX source to set the required values using the appropriate WiX XML elements. There are two different elements that are relevant:

关于这两个元素之间的差异,我引用 Bob Arnson(WiX 开发人员):您可以使用 XmlConfig 执行 XmlFile 支持的所有操作(以及更多),但它需要额外的XmlFile 不需要的创作.XmlFile 最擅长修改您正在安装的 XML 文件(例如,添加反映文件安装路径的属性);它无法在卸载时删除修改,但如果您的安装程序安装了该文件,无论如何它都会被卸载.XmlConfig 最擅长修改共享的 XML 文件,因为它支持卸载修改." (source).

With regards to the differences between these two elements, I quote Bob Arnson (WiX developer): "You can do everything (and more) that XmlFile supports with XmlConfig but it requires extra authoring that's not necessary with XmlFile. XmlFile is best at modifying XML files that you're installing (e.g., to add an attribute reflecting the installed path of a file); it can't remove the modifications at uninstall time but if your setup installed the file, it will be uninstalled anyway. XmlConfig is best at modifying shared XML files because it supports uninstalling the modifications." (source).

我发现这些 XML 内容非常繁琐,而且我可能没有使用最新最好的技术,但这里有一个快速示例.彻底测试 - 特别是卸载和升级方案 - 我完成的有限测试:

I find this XML stuff quite fiddly, and I may not use the latest and greatest techniques, but here is a quick sample. Test thoroughly - particularly uninstall and upgrade scenarios - limited testing done on my part:

这是我的测试 XML 文件(实际上是作为文件安装然后更新的).请检查您保存的文件的编码 - 报告了一些编码问题 - 不确定当前状态:

Here is my test XML file (that is actually installed as a file and then updated). Do check the encoding of the file you save - some issues with encoding have been reported - not sure what the current status is:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <ExistingConfig>
    <bindingRedirect oldVersion="0.0.0" newVersion="0.0.0" />
  </ExistingConfig>
</configuration>

这是将更新文件(并安装文件)的 WiX 片段.将上述 XML 测试文件放在 WXS 源文件旁边,或在构建 MSI 之前指定正确的源路径.

Here is the WiX snippet that will update the file (and install the file). Put the above XML test file next to your WXS source file, or specify the correct source path before building your MSI.

<Component Feature='ProductFeature'>

 <!--Installs the base file-->
 <File Source='app.config' />

 <!--Create New Element-->
 <util:XmlFile Id='XmlSettings1' File='[#app.config]' Action='createElement' 
               Name='MyConfig' ElementPath='//configuration' Sequence='1' />

 <!--Set New Value-->
 <util:XmlFile Id='XmlSettings2' File='[#app.config]' Action='setValue' 
              Name='newVersion' Value='6.6.8' ElementPath='//configuration/MyConfig' Sequence='2' />

<!--Set New Value-->
<util:XmlFile Id='XmlSettings3' File='[#app.config]' Action='setValue' 
              Name='Server' Value='Pusevov' ElementPath='//configuration/MyConfig' Sequence='3' />

<!--Update Existing Value, Existing Element-->
<util:XmlFile Id='XmlSettings4' File='[#app.config]'
  Action='setValue' Name='newVersion' Value='7.7.7' ElementPath='//configuration/ExistingConfig/bindingRedirect' Sequence='4' />

</Component>

我希望这有点道理.就像我说的,我发现这有时很繁琐且容易出错,但用于此类更新的其他工具也是如此.请记住首先尝试使用原始测试用例并进行测试安装以测试运行时错误.制作一些有用的小东西,然后在其上进行构建 - 这显然是不言而喻的,但很容易一次性尝试所有这些.洞里开火,找掩护!".

I hope that makes some kind of sense. Like I said, I find this fiddly and error prone at times, but so are other tools for this kind of updates. Remember to try first with a primitive test case and do test installs to test for runtime errors. Make something small that works and then build on it - which is obviously self-evident, but it is tempting to try it all in one go. "Fire in the hole, seek cover!".

一些保管链接:

  • Firegiant Tutorial on XML
  • Deleting XML element with XmlConfig extension in WIX using XPath
  • WIX util:xmlfile File name is Source attribute
  • WIX v3 and XmlConfig / XmlFile troubleshooting (resurrected from Wayback Machine)
  • Very step-by-step blog on WiX and XML
  • How do I force wix to update a file before manipulating it on an upgrade
  • Getting app settings for config files during WiX based install

这篇关于向 app.config 添加了新的应用程序设置,但 MSI 不会安装它(不会覆盖)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆