I don’t want to write comments or run code coverage on autogenerated code

The “warning CS1591: Missing XML comment for publicly visible type or member” issue

You’ve created a WCF service proxy and you’ve XML documentation turned on like the picture shows below.

image

Then you most likely will have a lot of warnings the next time you build your project like so:

image

Don’t despair the solution is close.

Solution

Find the Reference.cs file if you added a Service Reference manually or if you auto generated the Service Reference using the “svcutil.exe” utility open up the generated class.

Add the following line of code in your namespace:

#pragma warning disable 1591 //Disables CS1591 Warning

image

Auto generated code has lousy Code Coverage

Then you’ll be left with the issue that your auto generated code has lousy Code Coverage, if you haven’t written any tests against it that is. The question if you should write tests on auto generated code or not I leave it up to you. I’ll leave at that with the cowardly answer “it depends” Ler The before picture might look like this:

image

Notice how the auto generated namespaces are listed in Code Coverage.

Solution

This is as easily fixed as the XML Warning. In the file where you have the auto generated code use search and replace to add the

[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]

attribute to every class.

image

Finish things off with a Edit->Advanced->Format Document to get a nice formatting and your good to go!

image

Try compiling and watch as your code coverage goes up!

image

Cheers,

Hugo

Building and Unit Testing .Net 4.0 with Team Build 2008, the correct order

I’ve been helping my customer setting up .Net 4.0 build servers lately as you may have read in my previous post. In the previous post, I listed my challenges getting .Net 4 assemblies to build and unit test with Team Build 2008 so I thought It would be time to share the correct order to get the stuff working!

  1. Install Visual Studio 2010 Premium
  2. Install Visual Studio Team System 2008 Development Edition
  3. Install Visual Studio Team System 2008 Service Pack 1
  4. Install Team Build 2008
  5. Install Team Build Service Pack 1
  6. Configured Team Build 2008 to use MSBuild 4.0 instead of MSBuild 3.5. To do this edit %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\TFSBuildService.exe.config and set the MSBuildPath property to C:\Windows\Microsoft.NET\Framework\v4.0.21006\

That should do it! And if you install your build server in that order you won’t get the following error:

  • MSBUILD : warning : Visual Studio Team System for Software Testers or Visual Studio Team System for Software Developers is required to run tests as part of a Team Build
  • And you won’t replace the Microsoft.TeamFoundation.Build.targets with an incorrect workspace pattern:
    TFS Build 2008:
    $(COMPUTERNAME)_$(BuildDefinitionId)
    After VS 2010 installation:
    $(COMPUTERNAME)_$(BuildDefinitionId)_$(BuildAgentId)

Hope this summarizes how to install a build server that builds and unit tests .Net 4.0 applications with Team Build 2008.

Cheers!

Hugo

Building and Unit Testing .Net 4.0 with Team Build 2008

One of the tasks this week was to install and configure a new BizTalk 2010 build server in my clients environment. Pretty straight forward you may say huh? Well it would be if my client was using TFS 2010 but in this case we’re talking about a TFS 2008.

There are lots of posts like this great post explaining how to do this and the building part worked fine. But I kept getting error telling me that unit tests where not able to run because I didn’t have the correct version of Visual Studio installed. Anyway here are the steps I followed to succeed with this endeavor:

  • Install BizTalk 2010 compilation components
  • Installed Team Build 2008
  • Installed Team Build Service Pack 1
  • Configured Team Build 2008 to use MSBuild 4.0 instead of MSBuild 3.5. To do this edit %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\TFSBuildService.exe.config and set the MSBuildPath property to C:\Windows\Microsoft.NET\Framework\v4.0.21006\
  • Restarted the Team Foundation Build service
  • Tried a simple Hello World application without unit tests and the build worked fine.
  • Added some unit tests to the Hello World application and got error the following error MSBUILD : warning : Visual Studio Team System for Software Testers or Visual Studio Team System for Software Developers is required to run tests as part of a Team Build
  • Installed Visual Studio 2010 Premium
  • Got new error telling me that there was some problem with workspace creation during build, found this solution.
  • Changed the property $(COMPUTERNAME)_$(BuildDefinitionId)_$(BuildAgentId) to $(COMPUTERNAME)_$(BuildDefinitionId) in the file %ProgramFiles%\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\TFSBuildService.exe.config.
  • Got back the same old error MSBUILD : warning : Visual Studio Team System for Software Testers or Visual Studio Team System for Software Developers is required to run tests as part of a Team Build
  • Installed Visual Studio Team System 2008 Development Edition
  • Finally the build worked fine and all the unit tests ran successfully!

Hope this will summarize some of the issues you might run into when trying to build and unit test .Net 4.0 applications with Team Build 2008.

Cheers!

Hugo