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

时间:2023-01-16 19:46:58

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.

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

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.

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

Something like

  1. JobManager Solution
    • Manager.Core (with settings file)
    • Manager.Core(带设置文件)

    • Manager.UserInterface (with settings file)
    • Manager.UserInterface(带设置文件)

    • Manager.Extension
  2. JobManager Solution Manager.Core(带设置文件)Manager.UserInterface(带设置文件)Manager.Extension

  3. Importer Solution
    • Importer (with settings file)
    • 导入程序(带设置文件)

    • Service (with settings file)
    • 服务(带设置文件)

  4. 导入器解决方案导入程序(带设置文件)服务(带设置文件)

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)

可以看出,Manager.Core包含自己的配置文件来存储数据库连接信息和其他东西,而Importer包含自己的配置文件,存储导入目录的路径,以便知道从哪里获取需要导入的文件。数据库使用Manager.Core来做到这一点。 (这就是Manager.Core的用途,它包含了与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.

另一方面,服务是使用Importer的Windows服务,让它每小时左右运行一次,包含自己的错误记录路径配置设置。

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.

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

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

Manager.Core和Importer在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?

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

Kind regards, Michael

亲切的问候,迈克尔

2 个解决方案

#1


1  

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

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

They have a setting a CustomTool property of 'SettingsSingleFileGenerator'

他们设置了一个CustomTool属性'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:

对于名为Foo.settings的设置文件,其中包含带有范围的单个值“MyName”应用程序类型为字符串的应用程序,在名称空间Company.Properties(名为“Company”的项目的默认位置)中,值为“Shuggy”,如果您查看了dll in您可以在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"];
        }
    }
}

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)

这就是设置结构和默认值在与它们相关的dll中的持久性。从各种配置文件中读取实际值,具体取决于范围(以及可能的应用程序决定执行的程序更改)

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

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

#2


0  

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

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

#1


1  

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

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

They have a setting a CustomTool property of 'SettingsSingleFileGenerator'

他们设置了一个CustomTool属性'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:

对于名为Foo.settings的设置文件,其中包含带有范围的单个值“MyName”应用程序类型为字符串的应用程序,在名称空间Company.Properties(名为“Company”的项目的默认位置)中,值为“Shuggy”,如果您查看了dll in您可以在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"];
        }
    }
}

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)

这就是设置结构和默认值在与它们相关的dll中的持久性。从各种配置文件中读取实际值,具体取决于范围(以及可能的应用程序决定执行的程序更改)

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

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

#2


0  

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

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