This project is read-only.

StyleCop and MSBuild - problem with different loggers

May 10, 2011 at 10:16 AM


I have a question about the integration of StyleCop with TFS 2010 Build system. Our project is using StyleCop msbuild tasks that come with StyleCop (through "Import" directive in .csproj file) and we employ TFS 2010 to build it. Recently we have found out that if StyleCop msbuild task is run with a different logger (or simply with /noconsolelogger flag of msbuild), StyleCop still spits the informational messages to console, causing TFS Build to register these spits as errors.

 As a result, we have no other option but to turn off the stylecop in order to get builds going.

I was able to repro this situation easily by making a simple call from my local machine (simulating TFS Build on the server, where MYSOLUTION.SLN is the name of our solution which contains projects that have <Import> directive with StyleCop.targets file): 

MSBuild.exe MYSOLUTION.sln /m:1 /fl /p:SkipInvalidConfigurations=true /p:ServerBuildProjectItem=MYSOLUTION.sln /p:BinariesRoot="c:\build\Binaries" /p:TrackFileAccess=false p:OutDir="c:\build\Binaries\Release\\" /p:Configuration="Release"/p:Platform="Any CPU" /p:RunCodeAnalysis="False" /noconsolelogger


MSBuild.exe MYSOLUTION.sln /m:1 /fl /p:SkipInvalidConfigurations=true /p:ServerBuildProjectItem=MYSOLUTION.sln /p:BinariesRoot="c:\build\Binaries" /p:TrackFileAccess=false p:OutDir="c:\build\Binaries\Release\\" /p:Configuration="Release"/p:Platform="Any CPU" /p:RunCodeAnalysis="False" > 1.txt


In both cases, StyleCop msbuild tasks spits the following to console (not file):


MSBuild.exe Information: 0 : Loading add-ins from path C:\Program Files (x86)\StyleCop 4.5

MSBuild.exe Information: 0 : Loading assembly C:\Program Files (x86)\StyleCop 4.5\StyleCop.CSharp.dll

MSBuild.exe Information: 0 : Discovered SourceParser type CsParser

MSBuild.exe Information: 0 : Creating an instance of type CsParser

MSBuild.exe Information: 0 : Attempting to load add-in initialization Xml from path StyleCop.CSharp.CsParser.xml

MSBuild.exe Information: 0 : Attempting to load add-in initialization Xml from path StyleCop.StyleCopAddIn.xml

MSBuild.exe Information: 0 : Loading assembly C:\Program Files (x86)\StyleCop 4.5\StyleCop.CSharp.Rules.dll



Is there any way to tell StyleCop to use the logger supplied by MSBuild or default logger for process? With styleCop not respecting the logger settings from msbuild, it is always producing errors when we build the solution on the build server.

Any help will be highly appreciated,

May 10, 2011 at 11:17 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
May 10, 2011 at 11:18 AM

bug 6927. Someone will take a look.

May 11, 2011 at 9:50 AM


The text you are seeing is written out to any attached TraceListeners.

May 11, 2011 at 7:52 PM

In this case, the MSBuild task for StyleCop attaches these listeners or has these problems. It happens only in "Release" configuration and only for StyleCop - anything else in this project does not have this problem and outputs fine to file or to null console.

May 13, 2011 at 12:26 PM

Hmm. The StyleCop msbuild task isn't attaching listeners. Have a look here Could it be the defaulttracelistener is sending the output to the console window?

May 13, 2011 at 12:32 PM

Also. I've removed the Trace logging from onwards. Please confirm the problem has gone for you.

May 17, 2011 at 3:04 AM

Thanks! The problem has gone away with the new build. Thanks a lot for you help!