,以便对配置文件时,可用一个接口中使用。
命名空间: Microsoft.VisualStudio.ManagedInterfaces9
程序集: Microsoft.VisualStudio.ManagedInterfaces.WCF(在 Microsoft.VisualStudio.ManagedInterfaces.WCF.dll 中)
语法
声明
Public Interface IVsApplicationConfiguration _
Inherits IDisposable
public interface IVsApplicationConfiguration : IDisposable
public interface class IVsApplicationConfiguration : IDisposable
type IVsApplicationConfiguration =
interface
interface IDisposable
end
public interface IVsApplicationConfiguration extends IDisposable
IVsApplicationConfiguration 类型公开以下成员。
方法
名称 | 说明 | |
---|---|---|
![]() |
Dispose | 执行与释放或重置非托管资源关联的应用程序定义的任务。 (继承自 IDisposable。) |
![]() |
FileExists | 返回一个配置文件是否的值在磁盘上存在。 |
![]() |
FilePath | 返回配置文件的路径。 |
![]() |
LoadConfiguration | 加载特定层次结构/itemid 的配置。 |
![]() |
QueryEditConfiguration | 确定是否可以修改配置文件。 |
页首
事件
名称 | 说明 | |
---|---|---|
![]() |
ConfigurationChanged | ,该项目的配置更改时,发生。 |
页首
备注
IVsApplicationConfiguration 接口是 Configuration 对象的包装。
为当前项目使用 IVsApplicationConfiguration 提供更改通知和源代码管理用于在配置层次结构中的所有配置文件。 它还可用于协调对基础文本缓冲区的更改在可能打开的配置文件中的此实例和其他版本之间。
IVsApplicationConfiguration 句柄还将添加对的通知,删除和移动配置文件和文件夹在可能导致可以将无效的特定层次结构/itemid 配置的方法。 它还请注意注册配置更改通知的客户端。
示例
下面的代码示例演示如何使用 IVsApplicationConfiguration 界面修改配置文件。
/// Make sure that our custom WSDL importer extension is registered in /// the Metadata section of the configuration file for the current
/// project hierarchy and serviceProvider that gives access to required
/// services.
private static void EnsureCustomWsdlImporterRegistered
(IVsHierarchy hierarchy, IServiceProvider serviceProvider)
{
/// The IVsApplicationConfigurationManager service returns a
/// System.Configuration.Configuration object corresponding to
/// the given project's app.config or web.config file.
IVsApplicationConfigurationManager cfgMgr =
serviceProvider.GetService(typeof(IVsApplicationConfigurationManager))
as IVsApplicationConfigurationManager;
// Return the current application's configuration file by using
// the IVsApplicationConfiguration APIs. Make sure that the
// instance that is returned is disposed of correctly in order
// to clean up any event hooks or docdatas.
using (IVsApplicationConfiguration appCfg =
cfgMgr.GetApplicationConfiguration(hierarchy,
Microsoft.VisualStudio.VSConstants.VSITEMID_ROOT))
{
System.Configuration.Configuration cfg =
appCfg.LoadConfiguration();
// Check the file out from Source Code Control if it
// exists.
appCfg.QueryEditConfiguration();
/// After a System.Configuration.Configuration object
/// exists, use the"normal" .NET Framework configuration
/// APIs to return the sections that you want to modify.
ServiceModelSectionGroup sg =
ServiceModelSectionGroup.GetSectionGroup(cfg);
Type importerType = typeof(BindingPickerWsdlImportExtension);
if (!IsWsdlImporterRegistered(sg, importerType))
{
// If our custom WSDL importer is not registered, add
// it to the application's configuration file.
sg.Client.Metadata.WsdlImporters.Add(new
WsdlImporterElement(importerType));
cfg.Save();
}
}
}