更改.NET应用程序配置文件名

时间:2021-03-19 16:25:05

I have a VB6 app which calls a .NET assembly, which references settings from the app.config file. By default, .NET looks for a config file named after the VB6 app. How can I redirect it to use a different config file name? This needs to become the default config file so that e.g. WCF settings are read from it.

我有一个VB6应用程序调用.NET程序集,它引用app.config文件中的设置。默认情况下,.NET会查找以VB6应用程序命名的配置文件。如何重定向它以使用不同的配置文件名?这需要成为默认配置文件,以便例如从中读取WCF设置。

4 个解决方案

#1


You can't change it. Each AppDomain instance has a fixed app.config that is set via an AppDomainSetup instance when a new app domain is created. Although you can get the setup information via AppDomain.SetupInformation it has effectively become readonly at this point.

你无法改变它。每个AppDomain实例都有一个固定的app.config,它是在创建新的应用程序域时通过AppDomainSetup实例设置的。虽然您可以通过AppDomain.SetupInformation获取设置信息,但此时它已经有效地变为只读。

Given this, one option may be to create a new app domain from within your Main function and configure the domain to use the app.config you require.

鉴于此,一个选项可能是从您的Main函数中创建一个新的app域,并配置域以使用您需要的app.config。

#2


AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", @configFile);

#3


You can force the application to read a particular config file using

您可以强制应用程序使用读取特定的配置文件

System.Configuration.ConfigurationManager.OpenExeConfiguration(PATH_TO_CONFIG);

#4


Consider putting your configuration in a XML serialized object.

考虑将配置放在XML序列化对象中。

#1


You can't change it. Each AppDomain instance has a fixed app.config that is set via an AppDomainSetup instance when a new app domain is created. Although you can get the setup information via AppDomain.SetupInformation it has effectively become readonly at this point.

你无法改变它。每个AppDomain实例都有一个固定的app.config,它是在创建新的应用程序域时通过AppDomainSetup实例设置的。虽然您可以通过AppDomain.SetupInformation获取设置信息,但此时它已经有效地变为只读。

Given this, one option may be to create a new app domain from within your Main function and configure the domain to use the app.config you require.

鉴于此,一个选项可能是从您的Main函数中创建一个新的app域,并配置域以使用您需要的app.config。

#2


AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", @configFile);

#3


You can force the application to read a particular config file using

您可以强制应用程序使用读取特定的配置文件

System.Configuration.ConfigurationManager.OpenExeConfiguration(PATH_TO_CONFIG);

#4


Consider putting your configuration in a XML serialized object.

考虑将配置放在XML序列化对象中。