返回对应于项目的 Configuration 对象在 hierarchy 和 itemId 参数表示的级别的 IVsApplicationConfiguration 对象。
命名空间: Microsoft.VisualStudio.ManagedInterfaces9
程序集: Microsoft.VisualStudio.ManagedInterfaces.WCF(在 Microsoft.VisualStudio.ManagedInterfaces.WCF.dll 中)
语法
声明
Function GetApplicationConfiguration ( _
hierarchy As IVsHierarchy, _
itemId As UInteger _
) As IVsApplicationConfiguration
IVsApplicationConfiguration GetApplicationConfiguration(
IVsHierarchy hierarchy,
uint itemId
)
IVsApplicationConfiguration^ GetApplicationConfiguration(
IVsHierarchy^ hierarchy,
unsigned int itemId
)
abstract GetApplicationConfiguration :
hierarchy:IVsHierarchy *
itemId:uint32 -> IVsApplicationConfiguration
function GetApplicationConfiguration(
hierarchy : IVsHierarchy,
itemId : uint
) : IVsApplicationConfiguration
参数
hierarchy
类型:IVsHierarchy项目的 IVsHierarchy 。
itemId
类型:UInt32表示项目层次结构的根节点的常数 VSITEMID_ROOT 。
返回值
类型:Microsoft.VisualStudio.ManagedInterfaces9.IVsApplicationConfiguration
IVsApplicationConfiguration 对象。
备注
使用 VSITEMID_ROOT 检索该项的根级别的配置。
示例
下面的代码示例演示如何使用 GetApplicationConfiguration 方法返回 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();
}
}
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关详细信息,请参阅通过部分受信任的代码使用库。