是否有Visual Studio的外接一个配置文件类型? [英] Is there a config type file for Visual Studio Add-In?

查看:131
本文介绍了是否有Visual Studio的外接一个配置文件类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在创建一个Visual Studio插件,你怎么能利用一个app.config的加载项。如果我添加一个项目并部署它,然后在外接程序运行,并以编程方式尝试通过它不是捡的加载配置文件中的ConfigurationManager.AppSettings访问它。
我是不是做错了什么或有另一种方式来访问基于文件的配置设置加载项?

When creating a Visual Studio Add-In, how can you utilise an app.config for the add-in. If I add one to the project and deploy it then when the Add-In runs and I programmatically try to access it via the ConfigurationManager.AppSettings its not picking up the config file for the add-in.
Am I doing something wrong or is there another means to access file based configuration settings for an add-in?

推荐答案

ConfigurationManager.AppSettings拿起了您的AppDomain加载到的配置文件。该配置文件是典型地与入口点可执行相关联的一个。在你的情况,你无法控制你,所以你不能使用ConfigurationManager.AppSettings运行切入点的可执行文件,也没有在AppDomain。

ConfigurationManager.AppSettings picks up the configuration file for the AppDomain you are loaded into. That config file is typically the one associated with the entry point executable. In your case, you don't control the entry point executable nor the AppDomain you run in so you can't use ConfigurationManager.AppSettings.

你的问题基本上可以归结为我怎样才能有一个DLL相关的配置文件? ( C#DLL配置文件)。你需要做两件事情:

You question basically boils down to "How can I have a config file associated with a DLL?" (C# Dll config file). You need to do two things:

  1. 在添加应用程序配置文件的项目到项目,并确保它部署到同一文件夹作为你的DLL。
  2. 从您的DLL使用访问配置文件code是这样的:

  1. Add an Application Configuration File item to your project and make sure you deploy it to the same folder as your DLL.
  2. Access the config file from your DLL using code like this:

 string pluginAssemblyPath = Assembly.GetExecutingAssembly().Location;
 Configuration configuration = ConfigurationManager.OpenExeConfiguration(pluginAssemblyPath);
 string someValue = configuration.AppSettings.Settings["SomeKey"].Value;

对于使用卷影副本未装入普通的DLL这肯定会工作。我不知道VS如何加载其插件。如果您遇到的问题,让我知道,我可以发布一个变通的dll,它通过卷影副本被装入。

That will definitely work for regular DLLs that are not loaded using shadow copy. I'm not sure how VS loads its plugins. If you run into problems, let me know and I can post a work around for DLLs that get loaded via shadow copy.

这篇关于是否有Visual Studio的外接一个配置文件类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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