Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从具有不同名称的旧版本升级设置_C#_.net_Settings_App Config_Smartassembly - Fatal编程技术网

C# 从具有不同名称的旧版本升级设置

C# 从具有不同名称的旧版本升级设置,c#,.net,settings,app-config,smartassembly,C#,.net,Settings,App Config,Smartassembly,我们使用app.config存储用户设置,但更改了exe的名称。。。出于种种原因。我需要能够将设置从名为name1.exe的1.4版升级到现在名为name2.exe的1.5版 我尝试过几种方法,第一种是在Program.cs Main()中添加代码,在其中使用System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoamin

我们使用app.config存储用户设置,但更改了exe的名称。。。出于种种原因。我需要能够将设置从名为name1.exe的1.4版升级到现在名为name2.exe的1.5版

我尝试过几种方法,第一种是在Program.cs Main()中添加代码,在其中使用System.Configuration.ConfigurationManager.OpenExeConfiguration(System.Configuration.ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath来查找新设置文件应该放在的路径,然后搜索该设置的基本路径,以找到旧名称下的1.4版本,然后将1.4文件夹复制到路径中Properties.Settings.Default.Upgrade()正常工作的正确部分

我还尝试用旧的app.config文件替换新的app.config文件,并调用Properties.Settings.Default.Reload();并执行相同的操作,但只是重新启动应用程序

这些方法中的每一种都有效,即使在ide之外的发布模式下也是如此。但我们也使用SmartAssembly将一些其他DLL合并到exe的程序集中。智能组装必须执行一些未知的魔法,因为它在智能组装后无法工作

如果我手动将旧设置复制到新位置(替换app.config),然后尝试运行我的应用程序,但它甚至没有启动,它必须立即崩溃。同样,只有在使用SmartAssembly合并DLL之后。我已经将崩溃的范围缩小到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>

xml的最后一部分“section name=ExeName.Properties.Settings…” 旧设置文件中没有。我不知道为什么现在添加它,但是如果我在复制它时手动将它添加到旧的设置文件中,它就会工作


有什么办法可以做到这一点吗?

这可能不是正确的方法,但我只是编辑了xml以添加缺少的部分,它正在工作