【问题标题】:Visual Studio will not recognize new Settings FileVisual Studio 将无法识别新的设置文件
【发布时间】:2012-06-22 01:48:07
【问题描述】:

我正在尝试使用 C# 在我的 Windows 窗体应用程序中使用新的设置文件。

在我删除旧的设置文件 (Settings1.settings) 并创建新的设置文件 (Settings.settings) 之后。

当我开始编辑使用设置文件的代码时,我意识到无法识别新的设置文件。示例:

我们公司创建的命名空间中使用了一个自定义设置类,这导致了一些冲突。如何将代码指向正确的设置文件?

【问题讨论】:

  • 不要自己不要弄乱 .settings 文件,只有 IDE 应该这样做。尝试通过在解决方案窗口、项目+属性、设置中删除它来恢复,然后单击链接创建一个新的。
  • 这就是我对我目前在我的属性文件夹中的一个所做的。上一个都是代码,没有对应的Graphical table信息
  • 天哪,你完全迷路了。

标签: c# visual-studio-2010 settings


【解决方案1】:

我认识的派对迟到了。无论如何,我的解决方案是删除下面存储的设置

C:\Users\[username]\AppData\Local\[your program name]\

【讨论】:

    【解决方案2】:

    在尝试复制您所做的事情时,我注意到 Settings.Designer.cs 文件的命名空间来自此(我正在使用控制台应用程序进行测试)。

    namespace ConsoleApplication1.Properties {
    
    
        [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
        internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
    
            private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
    
            public static Settings Default {
                get {
                    return defaultInstance;
                }
            }
    
            [global::System.Configuration.UserScopedSettingAttribute()]
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
            [global::System.Configuration.DefaultSettingValueAttribute("False")]
            public bool Test {
                get {
                    return ((bool)(this["Test"]));
                }
                set {
                    this["Test"] = value;
                }
            }
        }
    }
    

    namespace ConsoleApplication1 {
    
    
        [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
        internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
    
            private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
    
            public static Settings Default {
                get {
                    return defaultInstance;
                }
            }
    
            [global::System.Configuration.UserScopedSettingAttribute()]
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
            [global::System.Configuration.DefaultSettingValueAttribute("False")]
            public bool Temp {
                get {
                    return ((bool)(this["Temp"]));
                }
                set {
                    this["Temp"] = value;
                }
            }
        }
    }
    

    如果您会注意到命名空间从 ConsoleApplication1.Properties 转到 ConsoleApplication1,那么如果您将 .Properties 添加到新设置文件的命名空间,它应该会解决您的问题。

    【讨论】:

    • 有一个类似的问题,在 VS 2015 中首次保存现有设置文件(从 VS 2010 迁移后)会导致类似的命名空间转移。谢谢!
    【解决方案3】:

    检查设置文件的命名空间,然后您有 2 个选项:

    1. 在 .cs 文件的开头添加 using 到此命名空间。

    2. 在每次尝试使用设置文件之前,将其整个命名空间写入。

    【讨论】:

    • 我在哪里可以找到该命名空间
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-20
    • 1970-01-01
    • 2014-08-30
    • 1970-01-01
    相关资源
    最近更新 更多