Bagikan melalui


IVsApplicationConfiguration Interface

Provides an interface for use when working with configuration files.

Namespace:  Microsoft.VisualStudio.ManagedInterfaces9
Assembly:  Microsoft.VisualStudio.ManagedInterfaces.WCF (in Microsoft.VisualStudio.ManagedInterfaces.WCF.dll)

Syntax

'Declaration
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

The IVsApplicationConfiguration type exposes the following members.

Methods

  Name Description
Public method Dispose Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. (Inherited from IDisposable.)
Public method FileExists Returns a value indicating whether a configuration file exists on disk.
Public method FilePath Returns the path for a configuration file.
Public method LoadConfiguration Loads the configuration for a given hierarchy/itemid.
Public method QueryEditConfiguration Determines if a configuration file can be modified.

Top

Events

  Name Description
Public event ConfigurationChanged Occurs when a project's configuration has changed.

Top

Remarks

The IVsApplicationConfiguration interface is a wrapper for Configuration objects.

Use IVsApplicationConfiguration to provide change notifications and source code control for all configuration files in the configuration hierarchy for the current project. It can also be used to coordinate changes to the underlying text buffers between this instance and other editors that may have the configuration file open.

IVsApplicationConfiguration also handles change notifications caused by adding, deleting, and moving configuration files and folders in a way that may cause the configuration for a given hierarchy/itemid to be invalidated. It also notifies clients that have registered for configuration change notifications.

Examples

The following code example demonstrates how to use the IVsApplicationConfiguration interface to modify a configuration file.

/// 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();
        }
    }
}

See Also

Reference

Microsoft.VisualStudio.ManagedInterfaces9 Namespace