Thursday, November 10, 2005 12:10 PM
Erwyn van der Meer
Problem with Code Analysis in Team Architect
Last Tuesday I encountered a problem with building code and checking-in code from within the Team Edition for Software Architects of Visual Studio 2005. To explain what went wrong, let me first explain the situation and tie in with some of my previous posts.
At home I run the Team Suite Trial SKU of Visual Studio 2005. My Team Foundation Server was running inside a Virtual Machine on a laptop. I had created a Team Project there with a "clean build" code analysis check-in policy.
I took this Virtual Machine with me to the office of LogicaCMG I work at. There I moved the Team Foundation Server (TFS) over to a machine running Virtual Server. On my laptop I installed a Virtual Machine running the Team Architect SKU that had been prepared by a colleague. This Virtual Machine is joined to a domain, while the TFS is running in workgroup mode. You might think that this might be a problem, but this works just fine. You can connect from a Team System Client joined to a domain to a TFS running in workgroup mode. The account name you login with on the client doesn't even have to match with an account on the TFS. When you connect to the TFS you are prompted once for a username and password.
After connecting to the TFS, I could fetch the project I created at home from source control. But when I wanted to compile the code I got the following error:

A NullReferenceException was thrown from the method Microsoft.Build.Tasks.CodeAnalysis.GenerateFullPathToTool(), causing an unexpected failure of the CodeAnalysis task. I guessed this was due to the fact that the Team Architect SKU does not support code analysis. You can see this through the absence of the Code Analysis tab in the Properties window for a Visual Studio Project. This a chart (from MSDN) that compares the features of the Team System Client SKUs:

But the error message was not really a polite way to say that code analysis is not suppored. A small investigation showed that I do have a C:\Program Files\MSBuild\Microsoft\VisualStudio\v8.0\CodeAnalysis\FxCopTask.dll file. This assembly is called by MSBuild when running the code analysis after compilation. Using .NET Reflector showed that the offending method is contained in this assembly. MSBuild tries to run code analysis because of this line in the .csproj file:
<RunCodeAnalysis>true</RunCodeAnalysis>
I could not find a way to turn this off in the Team Architect SKU other than through editing the project file in Notepad. The project compiled fine however, so I tried to check-in the code to Team System Source Control. This did not work. I got the following check-in policy violation:

The only way I found to circumvent this problem was to ignore the policy violation and override the policy to check-in anyway. So this begs the question: are architects not supposed to run code analysis if they check in code for a Team Project? How are architects supposed to collaborate on code when they are part of a Team Project that has a code-analysis check-in policy?
In most projects I work on, the application architect also has a reviewing role and is responsible for the quality of the code. This means that he or she should be the person setting the code analysis rules. But maybe Microsoft is aiming Team Architect at architects who are not involved in coding. But even if the architect does not write code and only designs the application using the Whitehorse designers, code still gets generated. This code has to be checked in by the architect and he/she might run into the code analysis problems I described above. If this is by design and not just a bug on my installation, it is an extra reason for me to get an upgrade to a non-trial version of Team Suite.
If you have any ideas about this, please let me know, by leaving a comment.
[Update 2005-11-16: In response to a post in the MSDN Forum for Team System, Microsoft has confirmed that code analysis is absent by design in Team Architect but that Visual Studio should not throw exceptions when building a project with code analysis enabled. I also reported this issue in the MSDN Product Feedback Center.]
Filed under: .NET