Easily switching between configuration files with MSBuild
A couple of days ago i wrote about Easily switching between App.Config files with MSBuild. Christophe Gijbels, a fellow compuwarrior, pointed out that developers usually need to copy more than a single App.Config file… I would propose to add a Folder for each Customer that contains all the specific configuration files. Eg
Now i have to configure MSBuild so that the right files are copied into the OutDir:
<!-- Define the CustomerPath depending on the choosen Configuration -->
<propertyGroup Condition=" $(Configuration) == 'Customer1 Debug' ">
<customerPath>Customer1</customerPath>
</propertyGroup>
<propertyGroup Condition=" $(Configuration) == 'Customer2 Debug' ">
<customerPath>Customer2</customerPath>
</propertyGroup>
<!-- Define AppConfig in the CustomerPath -->
<propertyGroup>
<appConfig>$(CustomerPath)\App.config</appConfig>
</propertyGroup>
<!-- Find all files in CustomerPath, excluding AppConfig -->
<itemGroup>
<customerFiles Include="$(CustomerPath)\*.*" Exclude="$(CustomerPath)\App.config" />
</itemGroup>
<target Name="AfterBuild">
<copy SourceFiles="@(CustomerFiles)" DestinationFolder="$(OutDir)" SkipUnchangedFiles="true"/>
</target>