Different config files in C# project

less than 1 minute read

It is almost certain that you would need different configuration for different environments. Here’s one way to maintain separate config files.

This should work for any number of configurations in the project- Release, Debug and whatever else custom configurations exist.

  1. Externally open ProjectName.csproj using a text editor.
  2. Import below after the last import. This is for the TransformXml task in step 3.
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.targets" />
  1. Add this task as BeforeBuild target like so:
  <Target Name="BeforeBuild">
      Destination="App.config" />

Leave a Comment