views:

45

answers:

2

Hi

I was trying to get some tests running inside a console application

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting; // this doesn't work

The error I'm getting is:

The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

Yet it all works in a seperate test project: alt text

Question: What is different?

A: 

You need to change the target framework of the ConsoleApplication to be .Net Framework 4 (NOT .NET Framework 4 Client Profile)

If you are targeting the .NET Framework 4 Client Profile, you cannot reference an assembly that is not in the .NET Framework 4 Client Profile. Instead you must target the .NET Framework 4.

You can't reference Microsoft.VisualStudio.QualityTools.UnitTestFramewor, because it is not part of the client profile framework.

EDIT: Sorry, you have that already ...

You need the reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework in your console application.

You can add it from C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies

The default Visual Studio Test project has this reference by default...

Svetlozar Angelov
I also had to add in <ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> into the csproj to get the test runner to recognise this assembly. http://www.bryancook.net/2009/12/manually-creating-ms-test-project.html
Dave
Have just found out that the console app doesn't run when these GUID's are in there.. it just fires up the test runner. Going to a seperate project for testing I think.. this was for fun!
Dave
A: 

You can create test project from visual studio and change the project output type from class library to console application.

Regards Aseem Bansal

Aseem Bansal