Search code examples
visual-studio-2012msbuildtfsbuildstylecop

Get TFS Build Server to obtain stylecop.settings file in root folder


We have a number of TFS projects in a single collection.

Each TFS project has a number of Visual Studio Solutions, with each sln file in it's own folder.

Each TFS project has a project-specific StyleCop.settings files in the root of the TFS project.

However, when we create a build for each solution, we get the build to only obtain the folder containing the solution (as recommended by Microsoft, to improve build performance). Therefore, we miss out on the StyleCop.settings file in the TFS project root.

Therefore, my question is:

How can I apply my settings file to the building of a solution, and meet the following criteria

  1. All StyleCop.settings files must be stored in source control.
  2. The number of StyleCop.settings files must be kept to a minimum (ideally no more than 1 per TFS project).
  3. Only the solution folder should be downloaded from TFS on a build.
  4. The build machine and developer's machines should not have to be modified with environment variables or similar.
  5. Each solution consists of multiple VS projects (i.e. multiple *.csproj files).

Appendix 1. Folder structure

For reference/clarity, here is an example of the folder structure I've described above. A TFS build will only check out the Application1 or Application2 folder (depending on which application it builds).

C:\Source\
  TfsProject1\
    stylecop.settings
    Application1\
      Application1.sln
    Application2\
      Application2.sln

Appendix 2. StyleCop NuGet

Just to note that we use the NuGet package StyleCop.MsBuild to integrate StyleCop into TFS - it is not installed directly on each machine, so any solution relying on that is out :)


Solution

  • In your build template Xaml file, edit and add a new "Download File" activity. In this activity mention the source location as the stylecop server location and the destination as your "sourcesdirectory" or where you want it to be. This will ensure that the file is downloaded during each build regardless of which solution.

    You don't have to maintain additional msbuild files for this purpose.