Skip to content

Commit

Permalink
Adding example of how to maintain multiple configuration files into t…
Browse files Browse the repository at this point in the history
…he same solution
  • Loading branch information
hmadrigal committed Apr 3, 2012
1 parent e8246c5 commit 0d4bd23
Show file tree
Hide file tree
Showing 10 changed files with 284 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MultipleConfigurationFilesSample", "MultipleConfigurationFilesSample\MultipleConfigurationFilesSample.csproj", "{65374B1E-9E0C-470A-9C98-F056A0EACD5B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Development|x86 = Development|x86
Production|x86 = Production|x86
Staging|x86 = Staging|x86
Testing|x86 = Testing|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{65374B1E-9E0C-470A-9C98-F056A0EACD5B}.Development|x86.ActiveCfg = Development|x86
{65374B1E-9E0C-470A-9C98-F056A0EACD5B}.Development|x86.Build.0 = Development|x86
{65374B1E-9E0C-470A-9C98-F056A0EACD5B}.Production|x86.ActiveCfg = Production|x86
{65374B1E-9E0C-470A-9C98-F056A0EACD5B}.Production|x86.Build.0 = Production|x86
{65374B1E-9E0C-470A-9C98-F056A0EACD5B}.Staging|x86.ActiveCfg = Staging|x86
{65374B1E-9E0C-470A-9C98-F056A0EACD5B}.Staging|x86.Build.0 = Staging|x86
{65374B1E-9E0C-470A-9C98-F056A0EACD5B}.Testing|x86.ActiveCfg = Testing|x86
{65374B1E-9E0C-470A-9C98-F056A0EACD5B}.Testing|x86.Build.0 = Testing|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace MultipleConfigurationFilesSample
{
public static class ApplicationConstants
{
public class AppSettings
{
public const string ServerSharedPath = @"ServerSharedPath";
public const string EnvironmentName = @"EnvironmentName";
public const string ApplicationDatabase = @"ApplicationDatabase";
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{65374B1E-9E0C-470A-9C98-F056A0EACD5B}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MultipleConfigurationFilesSample</RootNamespace>
<AssemblyName>MultipleConfigurationFilesSample</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Production|x86'">
<OutputPath>bin\x86\Production\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Testing|x86'">
<OutputPath>bin\x86\Testing\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Staging|x86'">
<OutputPath>bin\x86\Staging\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Development|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Development\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisIgnoreBuiltInRuleSets>false</CodeAnalysisIgnoreBuiltInRuleSets>
<CodeAnalysisIgnoreBuiltInRules>false</CodeAnalysisIgnoreBuiltInRules>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ApplicationConstants.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="app.development.config" />
<None Include="app.production.config" />
<None Include="app.staging.config" />
<None Include="app.testing.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<Target Name="ApplySpecificConfiguration" Condition="Exists('App.$(Configuration).config')">
<XslTransformation XmlInputPaths="App.config" XslInputPath="App.$(Configuration).config" OutputPaths="$(OutputPath)$(RootNamespace).$(OutputType).config" />
<Copy SourceFiles="$(OutputPath)$(RootNamespace).$(OutputType).config" DestinationFiles="$(OutputPath)$(RootNamespace).vshost.$(OutputType).config" />
</Target>
<Target Name="AfterBuild">
<CallTarget Targets="ApplySpecificConfiguration" />
</Target>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Configuration;

namespace MultipleConfigurationFilesSample
{
class Program
{
static void Main(string[] args)
{
var environment = ConfigurationManager.AppSettings[ApplicationConstants.AppSettings.EnvironmentName];
var serverSharedPath = ConfigurationManager.AppSettings[ApplicationConstants.AppSettings.ServerSharedPath];
Console.WriteLine(@"Environment: {0} ServerSharedPath:{1}", environment, serverSharedPath);
Console.ReadKey();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MultipleConfigurationFilesSample")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("MultipleConfigurationFilesSample")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("03547b57-ba96-42ed-8ade-0fb3716f6987")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="EnvironmentName" value="Debug" />
<add key="ApplicationDatabase" value="Data Source=DevelopmentServer\SQLEXPRESS;Initial Catalog=DevelopmentDatabase;Integrated Security=True;" />
<add key="ServerSharedPath" value="\\127.0.0.1" />
</appSettings>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>

<!-- Nodes to be replaces -->
<xsl:template match="/configuration/appSettings/add[@key='EnvironmentName']">
<add key="EnvironmentName" value="Development" />
</xsl:template>
<xsl:template match="/configuration/appSettings/add[@key='ApplicationDatabase']">
<add key="ApplicationDatabase" value="Data Source=DevelopmentServer\SQLEXPRESS;Initial Catalog=DevelopmentDatabase;Integrated Security=True;" />
</xsl:template>
<xsl:template match="/configuration/appSettings/add[@key='ServerSharedPath']">
<add key="ServerSharedPath" value="\\127.0.0.1" />
</xsl:template>


<!-- Copy all the remaining nodes -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>

<!-- Nodes to be replaces -->
<xsl:template match="/configuration/appSettings/add[@key='EnvironmentName']">
<add key="EnvironmentName" value="Production" />
</xsl:template>
<xsl:template match="/configuration/appSettings/add[@key='ApplicationDatabase']">
<add key="ApplicationDatabase" value="Data Source=PRODUCTION\SQLEXPRESS;Initial Catalog=ProductionDatabase;Integrated Security=True;" />
</xsl:template>
<xsl:template match="/configuration/appSettings/add[@key='ServerSharedPath']">
<add key="ServerSharedPath" value="\\PRODUCTION" />
</xsl:template>


<!-- Copy all the remaining nodes -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>

<!-- Nodes to be replaces -->
<xsl:template match="/configuration/appSettings/add[@key='EnvironmentName']">
<add key="EnvironmentName" value="Staging" />
</xsl:template>
<xsl:template match="/configuration/appSettings/add[@key='ApplicationDatabase']">
<add key="ApplicationDatabase" value="Data Source=StagingServer\SQLEXPRESS;Initial Catalog=StagingDatabase;Integrated Security=True;" />
</xsl:template>
<xsl:template match="/configuration/appSettings/add[@key='ServerSharedPath']">
<add key="ServerSharedPath" value="\\STAGING" />
</xsl:template>


<!-- Copy all the remaining nodes -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>

<!-- Nodes to be replaces -->
<xsl:template match="/configuration/appSettings/add[@key='EnvironmentName']">
<add key="EnvironmentName" value="Testing" />
</xsl:template>
<xsl:template match="/configuration/appSettings/add[@key='ApplicationDatabase']">
<add key="ApplicationDatabase" value="Data Source=TestingServer\SQLEXPRESS;Initial Catalog=TestingDatabase;Integrated Security=True;" />
</xsl:template>
<xsl:template match="/configuration/appSettings/add[@key='ServerSharedPath']">
<add key="ServerSharedPath" value="\\TESTING" />
</xsl:template>


<!-- Copy all the remaining nodes -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

0 comments on commit 0d4bd23

Please sign in to comment.