The approach I eventually came up with was to define a new MSBuild file, for each solution (and added as a solution item), to be used solely for the CI build server. This defines a target that has 2 jobs:
- Obtain the StyleCop file
- Run the normal build.
And it looks like this (this one includes a CI target and a Release target - obviously you can have as many targets as is sensible for your approach).
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<TF>"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\ide\tf.exe"</TF>
<TFFile>$/Project1/Settings.StyleCop</TFFile>
<OutputFile>.\StyleCop.Settings</OutputFile>
<TFCollection>http://mytfsserver:8080/tfs/DefaultCollection</TFCollection>
</PropertyGroup>
<Target Name="CI" DependsOnTargets="DownloadStyleCopSettings">
<!-- This target is intended for a Continuous integration build -->
<MSBuild Projects="Application1.sln" Properties="Configuration=Debug">
</MSBuild>
</Target>
<Target Name="Release" DependsOnTargets="DownloadStyleCopSettings">
<!-- This target is intended for a Release build.
It produces a Release (not Debug) build, and will increment Version numbers.
-->
</Target>
<!-- This target downloads the StyleCop settings file from the TFS Project root. -->
<Target Name="DownloadStyleCopSettings">
<Exec Command="$(TF) view /collection:$(TFCollection) $(TFFile) /noprompt /output:$(OutputFile)" />
</Target>
</Project>