ConfigManager Class

MSBuild Extension Pack

ConfigManager Class MSBuild Extension Pack Help 4.0.12.0
Task used to work with the .NET framework web.config and machine config files Valid TaskActions are:

ProtectConfigSection (Required: Section Optional: Site, Path, ConfigurationFileType, ProtectionProvider, SaveMode)

RemoveAppSetting (Required: SettingName Optional: Site, Path, ConfigurationFileType, SaveMode)

RemoveConnectionString (Required: SettingName Optional: Site, Path, ConfigurationFileType, SaveMode)

SetAppSetting (Required: SettingName Optional: Site, Path, SettingValue, ConfigurationFileType, SaveMode)

SetConnectionString (Required: SettingName Optional: Site, Path, SettingValue, ConfigurationFileType, SaveMode)

UnprotectConfigSection (Required: Section Optional: Site, Path, ConfigurationFileType, SaveMode)

Inheritance Hierarchy

SystemObject  Microsoft.Build.UtilitiesTask
    MSBuild.ExtensionPackBaseTask
      MSBuild.ExtensionPack.FrameworkConfigManager

Namespace: MSBuild.ExtensionPack.Framework
Assembly: MSBuild.ExtensionPack (in MSBuild.ExtensionPack.dll) Version: 4.0.0.0

The ConfigManager type exposes the following members.

Constructors

  NameDescription
Public methodConfigManager
Top
Properties

  NameDescription
Public propertyConfigurationFileType
Which .NET framework configuration file to update. Supports WebConfig and MachineConfig. Default is MachineConfig
Public propertyPath
Sets the Path to work on. Leave blank to target the .net framework web.config
Public propertyProtectionProvider
The encryption provider. Supports RSAProtectedConfigurationProvider and DataProtectionConfigurationProvider. Default is RSAProtectedConfigurationProvider
Public propertySaveMode
How should changes to the config file be saved? See http://msdn.microsoft.com/en-us/library/system.configuration.configurationsavemode.aspx for the list of values. Default is Minimal
Public propertySection
The config section to protect or unprotect
Public propertySettingName
The setting name to update.
Public propertySettingValue
The setting's value.
Public propertySite
Sets the Site to work on. Leave blank to target the .net framework web.config
Top
Examples

<Project ToolsVersion="4.0" DefaultTargets="Default" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <PropertyGroup>
        <TPath>$(MSBuildProjectDirectory)\..\MSBuild.ExtensionPack.tasks</TPath>
        <TPath Condition="Exists('$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks')">$(MSBuildProjectDirectory)\..\..\Common\MSBuild.ExtensionPack.tasks</TPath>
    </PropertyGroup>
    <Import Project="$(TPath)"/>
    <Target Name="Default">
        <ItemGroup>
            <MachineConfigSettings Include="settingName" >
                <Value>settingValue</Value>
            </MachineConfigSettings>
        </ItemGroup>
        <!-- Update machine.config app settings -->
        <MSBuild.ExtensionPack.Framework.ConfigManager TaskAction="SetAppSetting" SettingName="%(MachineConfigSettings.Identity)" SettingValue="%(Value)" SaveMode="Full"/>
        <ItemGroup>
            <ConnectionStrings Include="myAppDB">
                <Value>Server=MyServer;</Value>
            </ConnectionStrings>
        </ItemGroup>
        <!-- Update a website's connection strings -->
        <MSBuild.ExtensionPack.Framework.ConfigManager TaskAction="SetConnectionString" SettingName="%(ConnectionStrings.Identity)" SettingValue="%(Value)" ConfigurationFileType="WebConfig" Site="NewSite" Path="/" />
        <!-- Encrypt a website's connection strings -->
        <MSBuild.ExtensionPack.Framework.ConfigManager TaskAction="ProtectConfigSection" Section="connectionStrings"  ProtectionProvider="DataProtectionConfigurationProvider" ConfigurationFileType="WebConfig" Site="NewSite" Path="/" />
        <!-- Un-encrypt a website's connection strings -->
        <MSBuild.ExtensionPack.Framework.ConfigManager TaskAction="UnprotectConfigSection" Section="connectionStrings" ConfigurationFileType="WebConfig" Site="NewSite" Path="/" />
        <MSBuild.ExtensionPack.Framework.ConfigManager TaskAction="RemoveConnectionString" SettingName="%(ConnectionStrings.Identity)" ConfigurationFileType="WebConfig"  Site="NewSite" Path="/" />
        <!--- Remove a setting from a website -->
        <MSBuild.ExtensionPack.Framework.ConfigManager TaskAction="RemoveAppSetting" SettingName="removeMe" ConfigurationFileType="WebConfig"  Site="NewSite" Path="/" />
        <!-- Remove connection string 'obsoleteConnection' from machine.config file -->
        <MSBuild.ExtensionPack.Framework.ConfigManager TaskAction="RemoveConnectionString" SettingName="obsoleteConnection" />
    </Target>
</Project>
See Also

Reference