IVsApplicationConfigurationManager.GetApplicationConfiguration Method
Returns an IVsApplicationConfiguration object that corresponds to the Configuration object for a project at the level indicated by the hierarchy and itemId parameters.
Namespace: Microsoft.VisualStudio.ManagedInterfaces9
Assembly: Microsoft.VisualStudio.ManagedInterfaces.WCF (in Microsoft.VisualStudio.ManagedInterfaces.WCF.dll)
Syntax
'宣言
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
Parameters
- hierarchy
Type: Microsoft.VisualStudio.Shell.Interop.IVsHierarchy
The IVsHierarchy of the project.
- itemId
Type: UInt32
The constant VSITEMID_ROOT which represents the root node of the project hierarchy.
Return Value
Type: Microsoft.VisualStudio.ManagedInterfaces9.IVsApplicationConfiguration
An IVsApplicationConfiguration object.
Remarks
Use VSITEMID_ROOT to retrieve the configuration for the root level of the project.
Examples
The following code example demonstrates how to use the GetApplicationConfiguration method to return a IVsApplicationConfiguration object.
/// 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 Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.