如何更改应用程序配置文件名(AppName.exe.config)? [英] How to change application config file name (AppName.exe.config)?

查看:452
本文介绍了如何更改应用程序配置文件名(AppName.exe.config)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VB.NET中使用My.Settings对象,该对象会自动从AppName.exe.config文件获取应用程序设置. 如何在其他名称而不是AppName.exe.config的文件中存储配置? 我有几个程序,所有程序现在都使用自己的.config文件,但实际上它们都是克隆文件,如果更改某些设置,则需要编辑多个配置.

I use My.Settings object in VB.NET, which automatically gets application setting from AppName.exe.config file. How can I store config in file with other name, not AppName.exe.config? I have several programs, all of them now uses their own .config file, but in fact they all are clones, and if I change some setting I need to edit several configs.

推荐答案

这将与<appSettings>一起使用,不确定是否与设置"一起使用
设计时间
将app.config文件放在解决方案文件夹中,以便从项目上一层.对于解决方案资源管理器中的每个项目,请执行以下
-添加>现有项目
-在解决方案根目录中浏览到app.config>添加为链接(靠近添加"按钮的小箭头)

This will work with <appSettings>, not sure if it works with the Settings
Design time
Put the app.config file in the solution folder so one level up from a project. For each of your projects in the solution explorer do the following
- Add > Existing Item
- Browse to app.config in solution root > Add As Link (small arrow near to the Add button)

运行时间
您可以使用此代码加载配置(C#)

Run time
You can use this code to load config (C#)

var fileMap = new ConfigurationFileMap(pathToConfig);  
var configuration = ConfigurationManager.OpenMappedMachineConfiguration(fileMap);

这篇关于如何更改应用程序配置文件名(AppName.exe.config)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆