The problem:
I was configuring a new build on Bamboo CI server for a ASP.NET application. The solution built locally just fine, but consistently failed on the build server. This was the error:
(BeforeBuild target) ->
C:\Bamboo\src\MC-BUILD-JOB1\MyProject.Web\MyProject.Web.csproj(1851,5):
error : Could not write Destination file:
Access to the path 'C:\Bamboo\src\MC-BUILD-JOB1\MyProject.Web\Config\AppSettings.config' is denied.
The problem was in the following line:
<TransformXml Source="Config\AppSettings.Base.config"
Transform="Config\AppSettings.$(Configuration).config"
Destination="Config\AppSettings.config" />
So basically the TransformXml task was failing because the file Config\AppSettings.config was checked out as read-only in the build server.
Fortunately there is an easy workaround. The trick is to apply the XML transformations to a temp file and then use the Copy task with the OverwriteReadOnlyFiles attribute set to “True” to overwrite the file Config\AppSettings.config:
<TransformXml Source="Config\AppSettings.Base.config"
Transform="Config\AppSettings.$(Configuration).config"
Destination="Config\AppSettings_temp.config" />
<Copy SourceFiles="Config\AppSettings_temp.config"
DestinationFiles="Config\AppSettings.config"
OverwriteReadOnlyFiles="True" />
<Delete Files="Config\AppSettings_temp.config" />