Domanda

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 :)

È stato utile?

Soluzione

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.

Altri suggerimenti

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:

  1. Obtain the StyleCop file
  2. 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>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top