MSBuild and Private Accessors of Unit Tests

If you use a MSBuild on a build server to compile your visual studio solutions, you might know this problem: MSBuild won’t be able to compile your unit-test project, because it can’t find the private accessor classes, which are usually generated dynamically. The error looks like this:

The type or namespace name ‘MyClass_Accessor’ could not be found (are you missing a using directive or an assembly reference?

So basically, MSBuild does not generate those classes for you for some reason. However it works nice on your dev machine. Why? On your dev machine, Visual Studio uses the tool publicize.exe to create the private accessors in the background. This component is not present on your build server though.

Step 1: Deploy publicize component to the build server

Copy the following folder from your dev machine to your build server.
C:\Program Files\MSBuild\Microsoft\VisualStudio\v9.0\TeamTest
If your build-server is 64bit, also copy the folder to
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v9.0\TeamTest

Now if you run msbuild again, it should finally attempt to generate the private accessors. Howeve you will run into this error:

Could not load file or assembly ‘file:///C:\BuildServer\MySolution\MyProject\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll’ or one of its dependencies. The system cannot find the file specified.

This means we need to deploy an additional component..

Step 2: Deploy unit test framework to the build server

On your dev server, take the files Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll and Microsoft.VisualStudio.QualityTools.Resource.dll from the GAC (c:\windows\assembly) and copy them into the project folder of the unit test, according to the error message.

This worked for me (VS 2008, .NET 3.5). Note that the path names might differ if you have a different setup.

About these ads

2 Responses to “MSBuild and Private Accessors of Unit Tests”


  1. 1 Data4Ever November 1, 2011 at 12:12 pm

    hey adrian, you’re great!
    thanks for that post – it helped me in my further steps.
    keep on posting – you’ve got good stuff to share.

  2. 2 devtools.korzh.com September 20, 2013 at 11:09 am

    You helped me a lot. Many thanks!


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s





Follow

Get every new post delivered to your Inbox.

%d bloggers like this: