Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unit test project not building from build server

My VS2010 solution has a test project in it. The unit tests themselves reference the following namespace:

using Microsoft.VisualStudio.TestTools.UnitTesting; 

which is accessed via the following assembly on my PC:

Assembly Microsoft.VisualStudio.QualityTools.UnitTestFramework     C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\     PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll 

When I build the solution on my PC I have no issues; the tests will build and run okay.

We have an intranet page which we can use to kick off builds on a build server. When I build via this page, the build fails with the following errors:

Generator.cs(3,17): error CS0234: The type or namespace name 'VisualStudio'  does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) 

The obvious problem would be that the Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll mentioned above is not present on the build server. I thought this was would be installed with VS2010, and since the projects in my solution build .NET 4.0 targets, I would expect this to be installed on the build server.

What is the easiest way to resolve this? The build server is out of my jurisdiction and I don't particular want to log a job to get new libraries installed on to it.

like image 427
LeopardSkinPillBoxHat Avatar asked Jan 19 '12 04:01

LeopardSkinPillBoxHat


People also ask

Does MSBuild run unit tests?

You can use unit testing functionality in Visual Studio to test an MSBuild custom task before distribution to ensure the correctness of the code.

How do you create a unit test project?

On the Create a new project page, type unit test into the search box. Select the project template for the test framework that you want to use, for example MSTest Test Project or NUnit Test Project, and then select Next. On the Configure your new project page, enter a name for your project, and then select Create.

How do I add a unit test project in .NET core?

Follow these steps to add the test project: Step 1: Right-click on the project solution and select the Add -> New Project option. Step 2: Select NUnit test project (. NET Core) and click Next.


2 Answers

The .UnitTestFramework.dll sits in C:\Program Files... folder and you have a reference to it.

  1. Create directory under your source control eg. Source/Binaries
  2. Copy the said dll into Source/Binaries
  3. Remove the reference to .UnitTestFramework.dll from your unit test assembly
  4. Add the reference to .UnitTestFramework.dll to your unit test assembly but this time select the dll that is now under Source/Binaries

After that you can checkin your changes (make sure the Source/Binaries folder is checked in) and build the solution. When build server builds the solution it should get the dll from the source control.

like image 135
Toni Parviainen Avatar answered Oct 17 '22 19:10

Toni Parviainen


The specific answer for me and a Visual Studio 2010 solution was:

  1. Install "Test Agent 2010" from Visual Studio Agents 2010
  2. Restart Windows
  3. Install Visual Studio 2010 Service Pack 1
  4. Restart Windows
  5. Ensure the projects References are updated to point at "Microsoft.VisualStudio.QualityTools.UnitTestFramework" "10.1.0.0" and not "10.0.0.0".
like image 43
Dean Taylor Avatar answered Oct 17 '22 19:10

Dean Taylor