简体   繁体   English

从旧版本升级设置并使用其他名称

[英]Upgrade settings from old version with different name

We use app.config to store user settings, but changed the name of the exe... for reasons. 我们使用app.config来存储用户设置,但是出于某些原因更改了exe的名称。 I need to be able to upgrade the settings from version 1.4 called name1.exe to version 1.5 now called name2.exe. 我需要能够将设置从名为name1.exe的1.4版升级到现在称为name2.exe的1.5版。

I've tried several methods, the first was to add code in Program.cs Main() where it would use System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath to find the path where the new settings file should go, and search the base path of that setting to find the 1.4 version under the old name, then copy the 1.4 folder into the correct part of the path where the Properties.Settings.Default.Upgrade() would work like normal. 我尝试了几种方法,第一种方法是在Program.cs Main()中添加代码,以在其中使用System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath来查找新设置的路径文件应该去,并搜索该设置的基本路径以找到旧名称下的1.4版本,然后将1.4文件夹复制到该Properties.Settings.Default.Upgrade()可以正常工作的路径的正确部分。

I've also tried replacing the new app.config file with the old one and calling Properties.Settings.Default.Reload(); 我也尝试过用旧的替换新的app.config文件,并调用Properties.Settings.Default.Reload();。 and doing the same but just restarting the application. 并执行相同操作,只是重新启动应用程序。

Each of those methods worked, even in release mode outside the ide. 这些方法中的每一个都有效,即使在ide之外的发布模式下也是如此。 But we also use SmartAssembly to merge some other dlls into our exe's assembly. 但是,我们也使用SmartAssembly将其他一些dll合并到exe的程序集中。 Smart assembly must do some unknown magic, because it doesn't work after being SmartAssembled. 智能装配必须做一些未知的魔术,因为在智能装配后它无法工作。

If I manually copy the old settings to the new location (replacing the app.config) then try to run my app doens't even start, it must crash right away. 如果我手动将旧设置复制到新位置(替换app.config),然后尝试运行我的应用程序甚至无法启动,则它必须立即崩溃。 Again, only after using SmartAssembly to merge our dlls. 同样,仅在使用SmartAssembly合并我们的dll之后。 I've narrowed the crashing down to this part in the xml... 我将崩溃范围缩小到了xml的这一部分...

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings">
            <section name="DllNameA.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
            <section name="DllNameB.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
            <section name="ExeName.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>

That last part of the xml "section name=ExeName.Properties.Settings..." was not there in the old settings file. xml的最后一部分“部分名称= ExeName.Properties.Settings ...”在旧的设置文件中不存在。 I'm not sure why it's added now, but it works if I manually add it to the old settings file when copying it over. 我不确定为什么现在要添加它,但是如果我在复制时手动将其添加到旧的设置文件中,则可以使用。

Is there a way to make this work? 有没有办法使这项工作?

这可能不是执行此操作的正确方法,但是我只是编辑了xml以添加缺少的部分,因此它可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM