Team Development - How do I Setup MSBuild correctly?

Oct 8, 2012 at 2:01 AM
Edited Oct 8, 2012 at 6:50 AM

Hello:

I was following this tutorial: http://stylecop.codeplex.com/wikipage?title=Setting%20Up%20StyleCop%20MSBuild%20Integration&referringTitle=Documentation in order to get stylecop running smoothly.

I managed to make it run fine. The problem is that it is necessary to install StyleCop in every pc that is going to open the Visual Studio project. I tried to solve it following the mentioned tutorial and the comments below it, but it hasn't worked (StyleCop tests only run if the .csproj is referencing the StyleCop installation directory).

Currently I have copied all the files installed by StyleCop to my $(SolutionDir), inside it is the "StyleCop.Targets" too. I modified the files as it can be seen bellow but it doesn't work. When I build the project, the Stylecop tests doesn't run.

Screenshot of my project file structure: http://i50.tinypic.com/152lr9i.png

Configuration that works:

  • .csproj

 

...
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <Import Project="$(ProgramFiles)\MSBuild\StyleCop\v4.7\StyleCop.targets" />
...

 

  • StyleCop.Targets

 

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!-- Specify where tasks are implemented. -->
  <UsingTask AssemblyFile="$(MSBuildExtensionsPath)\..\StyleCop 4.7\StyleCop.dll" TaskName="StyleCopTask"/>
....

 

Configuration that doesn't work (NEEDED)

  • .csproj

 

....
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\Tools\StyleCop\StyleCop.targets" />
....

 

  • StyleCop.Targets

 

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!-- Specify where tasks are implemented. -->
  <UsingTask AssemblyFile="$(SolutionDir)\Tools\StyleCop.dll" TaskName="StyleCopTask"/>
....

 

Thanks for any help you guys can give me! :)

Bye!

Coordinator
Oct 8, 2012 at 6:24 AM
If I recall correctly $(SolutionDir) only exists when you are in the VS IDE and not if trying to build via the cmd line.

Change the path to be a relative path to your Stylecop directory and it should be fine.


~A.

Oct 10, 2012 at 5:26 AM
Edited Oct 10, 2012 at 5:26 AM

Hello andyr:

I changed both paths like this:

  • .csproj (This is the project for wich I'm running the StyleCop tests and it is inside the Classhare folder, outside of this folder is the "Tools" folder wich contatins StyleCop

 

....
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="..\Tools\StyleCop\StyleCop.targets" />
.....

  • Stylecop.Targets (This file is inside Tools/StyleCop with all the other stylecop files and dll's)

 

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!-- Specify where tasks are implemented. -->
  <UsingTask AssemblyFile="StyleCop.dll" TaskName="StyleCopTask"/>
....

 

But it still doesn't work (it starts the build but then it shows a red message saying that couldn't find the StyleCop.dll), can you please give me an example of how can I leave the paths in order for this to work.

 

The screenshot on the first post (tinychat url) shows better how my folders are arranged.

Thank you so much for your answer!!! :)