简体   繁体   English

如何编码C#exe文件以指向其他位置的配置文件

[英]how to code an C# exe to point to an config file in a different location

How would I go about coding my C# console program to look to a different directory for its app.config file? 我该如何编码我的C#控制台程序以查找其app.config文件的其他目录? I would like the config file to sit in the program files folder but have the exe inside the startup folder. 我希望配置文件位于程序文件文件夹中,但将exe放在启动文件夹中。

You can create a new application domain, and configure it to use configuration file other than default one. 您可以创建一个新的应用程序域,并将其配置为使用默认域以外的配置文件。 Here is how to create and configure app domain : http://msdn.microsoft.com/en-us/library/c8hk0245.aspx . 以下是创建和配置应用程序域的方法: http : //msdn.microsoft.com/zh-cn/library/c8hk0245.aspx

Here is config file property. 这是配置文件属性。 http://msdn.microsoft.com/en-us/library/system.appdomainsetup.configurationfile.aspx http://msdn.microsoft.com/zh-CN/library/system.appdomainsetup.configurationfile.aspx

After you created a domain you can invoke DoCallBack on the created app domain http://msdn.microsoft.com/en-us/library/system.appdomain.docallback.aspx to start your application. 创建域后,可以在创建的应用程序域http://msdn.microsoft.com/en-us/library/system.appdomain.docallback.aspx上调用DoCallBack以启动您的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM