Best Practice: Simplified Azure ServiceConfiguration

Posted by Nilay Parikh and last modified on Tue Jun 12, 2018.

Best practices are considered as the most secure and optimised, but they don’t come free. Sometimes the cost is additional development and support efforts, and I am happy to concede the opposite argument that it is not always true.

If ServiceConfiguration.cscfg is not storing any sensitive information, the following simplified best practice would be lightweight and easy to manage. It is just using Visual Studio built-in feature called “Config Transformation”. Follow the simple hack and voilà,

1. Create transformation ServiceConfiguration.cscfg file set

  • Make a copy of ServiceConfiguration.cscfg.
  • Rename copy to ServiceConfiguration.Base.cscfg.
  • For each build configuration (e.g. Staging, Production), create a ServiceConfiguration.<build Config name>.cscfg file.

2. Edit the project

  • In Solution Explorer, right-click the project and click Unload Project. The project is marked (unavailable).
  • In Solution Explorer, right-click the unavailable project and click Edit . The project file opens in the Visual Studio XML Editor.
  • Find the following node
      <ServiceDefinition Include="ServiceDefinition.csdef" />
      <ServiceConfiguration Include="ServiceConfiguration.cscfg" />
  • Replace with following
      <ServiceDefinition Include="ServiceDefinition.csdef" />
      <ServiceConfiguration Include="ServiceConfiguration.cscfg" />
      <None Include="ServiceConfiguration.Base.cscfg">
      <None Include="ServiceConfiguration.Staging.cscfg">
      <None Include="ServiceConfiguration.Production.cscfg">
  • Add the following at the end of the .ccproj file, just above </Project>
    <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets" />
  <Target Name="BeforeBuild">
      <TransformXml Source="ServiceConfiguration.Base.cscfg" Transform="ServiceConfiguration.$(Configuration).cscfg" Destination="ServiceConfiguration.cscfg" />

3. Save, Close and Reload.

  • Save, and close the project file.
  • In Solution Explorer, right-click the unavailable project and click Reload Project.

For advanced user, you can also add the namespace to your ServiceConfiguration.cscfg or sometimes due to XML Transformation requirement it is essential.

<sc:ServiceConfiguration serviceName="NilayCornerService" osFamily="1" osVersion="*" xmlns:sc="" xmlns:xdt="">
  <sc:Role name="NilaysChef">
    <sc:Instances count="1" />
      <sc:Setting name="MyConnectionString" value="****************************" />

If you are looking for some tooling help then worth exploring SlowCheetah - XML Transforms

Small development teams can also adopt the same transformation practices with CI/CD builds. You may also like to refer How to deploy solution to different instance size for Azure environments


Any views or opinions expressed are solely those of the author and do not represent any other person or organisation. THE ARTICLE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. IN NO EVENT SHALL THE AUTHOR(S) OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY.