Using Visual Studio 2010 code analysis with TeamCity

I'm using TeamCity 5.1.2 to perform my build by calling an MSBuild script. The script basically calls the MSBuild task on my Visual Studio 2010 solution file.

The projects within my solution have Visual Studio 2010 code analysis turned on so the MSBuild task also performs static analysis of my code using the Visual Studio 2010 FxCop tool.

The problem comes when I try to build with some of these code inspection messages suppressed. I have created a 'GlobalSuppressions.cs' file in my project and added the messages I want suppressed to it. Unfortunately this doesn't suppress anything when I run my TeamCity build.

I've tried running the same MSBuild script that TeamCity uses on my desktop and the messages are correctly suppressed. It is only when I build on my TeamCity server that the message suppressions are ignored at build time. I've even tried running the exact same compile commands that are executed by TeamCity (taken from the TeamCity log) on my desktop, but still the messages are suppressed when run on my desktop but not on the TeamCity server.

Does TeamCity use some weird special build argument that is hidden from sight or have some non-standard environment variables defined that could cause this?

Thanks in advance,


TeamCity sets it's implementation of MSBuild logger. In the implementation of the logger we does not react on custom logging event. Do you know how does embedded code analysis logs it's messages? Could you please attach sample project and xml log.

TeamCity provides support of FxCop as FxCop build runner. It is also possible to import FxCop report in TeamCity.
Please have a look at

Service message is a text message that could be printed with any task, for example <Message> MSBuild task.


Did you resolve this issue?   I suspect that this problem could be related to the fact the Visual Studio IDE defines a constant called CODE_ANALYSIS when you run the build within the IDE and this constant is not defined when you run the build within Team City.

The FxCop rules you suppress with the [SuppressMessageAttribute] are only conditionally compiled when the CODE_ANALYSIS constant is defined (

So the effect you would see on the build server if the constant is not defined is that the rules continue to trigger even though you thought you suppressed them (inline in the source code or in the GlobalSuppressions file).




I did indeed resolve this issue; after a fair amount of trial and error I discovered that I need to define the CODE_ANALYSIS property in my MSBuild call as you correctly identified.

<MSBuild Projects="$(SolutionFile)" Targets="Rebuild" Properties="Configuration=$(Configuration);Platform=$(Platform);SignAssembly=false;DefineConstants=CODE_ANALYSIS" ContinueOnError="false" />


Please sign in to leave a comment.