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

2023-09-03 11:30:53 作者:心静无尘

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

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.

推荐答案

您不能改变它。每一个AppDomain中实例都有一个固定的app.config正在通过 AppDomainSetup 实例设置,创建一个新的应用程序域的时候。虽然你可以通过设置信息 AppDomain.SetupInformation 已经有效地只读此时成了。

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.

鉴于此,一种选择可能是从你的主要函数中创建一个新的应用领域,并配置域使用您需要在app.config。

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.