如何在 VS 2008 和 .NET 中使用跨多个解决方案和项目的设置

发布于 2024-07-18 00:29:22 字数 1116 浏览 5 评论 0原文

我不太确定 .NET 和 C# 3.5 如何处理跨多个项目以及多个解决方案的应用程序的设置。 也许有人可以帮我解决问题。

我有 2 个解决方案,都包含多个项目。 其中一些项目在 Properties 文件夹下包含一个 Setttings.settings 文件,其中包含该项目中的源文件所需的特定配置变量。

类似

  1. JobManager解决方案
    • Manager.Core(带有设置文件)
    • Manager.UserInterface(带有设置文件)
    • 管理器.扩展
  2. 导入器解决方案
    • 导入器(带有设置文件)
    • 服务(带有设置文件)

可以看出,Manager.Core 包含自己的配置文件来存储数据库连接信息和其他内容,而 Importer 包含自己的配置文件,存储导入目录的路径,以了解从哪里获取需要使用 Manager.Core 导入数据库的文件。 (这就是 Manager.Core 的用途,它包含与数据库一起使用的所有查询和插入)

另一方面,Service 是一个 Windows 服务,它使用导入器并让它运行每个小时左右,包含其自己的错误日志记录路径的配置设置。

现在,当我编译服务时,只有 1 个名为 Service.exe.config 的配置文件,其中仅包含服务项目中指定的配置参数。 我的第一个方法是复制 Service.exe.config 中 Manager.Core 和 Importer 的每个设置条目。 但测试表明,不知何故,导入器的参数存在并被使用。

Manager.CoreImporter 的设置不存在于 Service.exe.config 中时,它们的设置存储在哪里?

Manager.Core 的设置是否也存在,这意味着无需在服务设置文件中复制这些配置设置的条目?

亲切的问候, 迈克尔

I'm not quite sure how .NET and C# 3.5 handles the settings of applications spanning over multiple projects as well as multiple solutions. Maybe someone can help me clear things up.

I've got 2 solutions, both containing several projects. Some of those projects contain a Setttings.settings file under the Properties folder, containing specific configuration variables required by the source files in this project.

Something like

  1. JobManager Solution
    • Manager.Core (with settings file)
    • Manager.UserInterface (with settings file)
    • Manager.Extension
  2. Importer Solution
    • Importer (with settings file)
    • Service (with settings file)

As can be seen, Manager.Core contains its own configuration file to store database connection information and other stuff, whereas the Importer contains its own configuration files storing the paths to the import directories to know where to get the files it needs to import into the database using Manager.Core to do so. (that's what Manager.Core is there for, it contains all the queries and inserts to work with the DB)

Service, on the other hand, is a Windows Service which uses the Importer and let's it run every hour or so, containing its own configuration settings for error logging paths.

Now when I compile the Service, there is only 1 configuration file called Service.exe.config, containing only the configuration parameters specified in the Service project. My first approach was to duplicate every setting entry of Manager.Core and Importer in Service.exe.config. But testing showed that, somehow, the parameters of the Importer are present and used.

Where are the settings for Manager.Core and Importer stored when they are not present in Service.exe.config?

Are the settings of Manager.Core present, too, meaning it's unnecessary to duplicate the entries of those configuration settings in the Service settings file?

Kind regards,
Michael

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

ゞ花落谁相伴 2024-07-25 00:29:23

设置默认值通常生成为代码,然后编译到生成的 dll 中。

它们有一个设置为“SettingsSingleFileGenerator”的 CustomTool 属性,

对于名为 Foo.settings 的设置文件,包含单个值“MyName”,范围为字符串类型的应用程序,值为“ Shuggy”位于命名空间 Company.Properties(名为“Company”的项目的默认位置)中,如果您查看反射器中的 dll,您会在 Company.Properties 命名空间中找到一个类,如下所示:

[GeneratedCode(
"Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator"
,"9.0.0.0")] 
[CompilerGenerated]
internal sealed class Foo : ApplicationSettingsBase
{
    private static Settings defaultInstance = 
        ((Settings) SettingsBase.Synchronized(new Settings()));

    public static Settings Default
    {
        get { return defaultInstance; }
    }


    [ApplicationScopedSetting]
    [DefaultSettingValue("Shuggy")]
    [DebuggerNonUserCode]
    public string MyName
    {
        get
        {
            return (string) this["MyName"];
        }
    }
}

这就是设置结构和默认值的方式保留在与其相关的 dll 中。 实际值是根据范围(以及应用程序决定执行哪些编程更改)从各种配置文件中读取的。

有关如何使用这些值的更高级别视图,请参阅 本文

Settings defaults are normally generated into code which is then compiled into the resulting dll

They have a setting a CustomTool property of 'SettingsSingleFileGenerator'

For a Setting file called Foo.settings containing a single value 'MyName' with scope Application of type string with value "Shuggy" in namespace Company.Properties (the default location for a project called 'Company') if you looked at the dll in reflector you would find a class in the Company.Properties namespace looking like this:

[GeneratedCode(
"Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator"
,"9.0.0.0")] 
[CompilerGenerated]
internal sealed class Foo : ApplicationSettingsBase
{
    private static Settings defaultInstance = 
        ((Settings) SettingsBase.Synchronized(new Settings()));

    public static Settings Default
    {
        get { return defaultInstance; }
    }


    [ApplicationScopedSetting]
    [DefaultSettingValue("Shuggy")]
    [DebuggerNonUserCode]
    public string MyName
    {
        get
        {
            return (string) this["MyName"];
        }
    }
}

This is how settings structure and default values are persisted within the dlls which they are relevant to. The actual values are read from various config files depending on the scope (and possibly what programmatic changes the app decides to do)

For a higher level view on how these are intended to be used see this article

苄①跕圉湢 2024-07-25 00:29:23

没有使用这些,但您可以用解决方案中单个文件的链接替换它们吗?

Not used these but could you replace them with links to a single file in the solutions?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文