Gated build using release template gives access denied exception while processing tokens

We recently had a case where the customer was using a gated build which was triggering a release.
Tokens were also being processed as part of this build. We have come across an issue with this configuration. TFS and Release Management versions used were both 2013 Update 4.

Normally, the build and release would work fine, say for example if we modify a file in the project/ workspace and do a check-in – this will trigger the gated build, process the tokens and also does the release successfully.

However, the issue happens if we do a check-in after modifying the web.config file.This time around, the build would fail, giving an access denied message as shown below:



Steps to Reproduce:

  • Create a build definition and select the trigger as gated check-in.

  • Specify the project to be built (for which you want to process tokens and do a release as part of the build), build controller, drop location etc.

  • In the process tab, choose ReleaseDefaultTemplate11.1.xaml as the build template.

    Note: The Release templates can be found in the below location on your Release Management server:
    Program Files (x86)\Microsoft Visual Studio 12.0\Release Management\bin
    You would have to get a copy of this definition and check it in to your team project in TFS.

  • Make sure you have also set the property Release Build (Under the Release section in the Process tab) to True.

  • Please not that you will have to make the necessary changes in the release definition on the Release Management server so that the tokens are replaced properly and also associate it with the build definition created in the above steps. Here is an article that explains about using tokens with Release Management.

  • Make a change to any of the files in the workspace except the web.config file and do a check-in.

    Verify that the build and release completes successfully.

  • Now, make a change to the web.config file in the workspace and check it in to trigger a build. The build will fail with the error message shown in the above screen shot.

The failure happens when the build executes the token replacement logic in the build agent working folder. Below are the sequence of events that happen, from the build logs:

Rename Files00:00:00



    • Value: C:\Builds\5\T2\Repro Template\Sources\New Folder\WebApplication1\WebApplication1\Web.config


    • To: C:\Builds\5\T2\Repro Template\Sources\New Folder\WebApplication1\WebApplication1\Web.config

Make x.y.token Writable00:00:00


    • TargetObject:


    • Result:

Make x.y Writable00:00:00


    • TargetObject:


    • Result:

Delete x.y file00:00:00


    • TargetObject:


    • Result:
Exception Message: Access to the path 'C:\Builds\5\T2\Repro Template\Sources\New Folder\WebApplication1\WebApplication1\Web.config' is denied. (type UnauthorizedAccessException) Exception Stack Trace: at System.Activities.Statements.MethodExecutor.InvokeAndUnwrapExceptions(Func`3 func, Object targetInstance, Object[] actualParameters) at System.Activities.Statements.MethodResolver.SyncMethodExecutor.BeginMakeMethodCall(AsyncCodeActivityContext context, Object target, AsyncCallback callback, Object state) at System.Activities.Statements.MethodExecutor.BeginExecuteMethod(AsyncCodeActivityContext context, AsyncCallback callback, Object state) at System.Activities.AsyncCodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)


The access denied exception happens when the build attempts to delete the web.config file, within the source directory in the build agent’s working folder, to replace tokens.


How to work around this

We have identified that the issue happens only with the ReleaseDefaultTemplate11.1.xaml template. You can use the ReleaseTfvcTemplate.12.xaml instead, to work around this issue. This should also be present in Program Files (x86)\Microsoft Visual Studio 12.0\Release Management\bin

While using the ReleaseTfvcTemplate.12 template, make sure you set the value for the Configurations to Release property in the build definition, under the Release section in the Process tab.

Unlike the 11.1 template, ReleaseTfvcTemplate.12.xaml copies the binaries to the bin folder within the agent directory, and executes the token replacement logic there.

Content Created By : Sreeraj Rajendran
Content Reviewed By : Romit Gulati


Comments (0)

Skip to main content