165

I am getting following error in my C# visual studio project:

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

I also tried to find the microsoft.dll file but couldn't get any reference. Am I searching the wrong DLL?

using Microsoft.VisualStudio.TestTools.UnitTesting;  
using Kya.MsFx.Services.Swiper;

namespace Kya.MsFx.Devices.Swiper.Test
{
[TestClass]
public class SwiperWindowTest
{

    private SwiperWebServiceHost m_SwiperWS = null;
    /// <summary>
    ///     start web service on a separate thread, so tests 
    ///     can be executed withut blocking the application thread
    /// </summary>
    [ClassInitialize]
    public void SetupSwiperTests() {

        m_SwiperWS = SwiperWebServiceHost.StartService();

    }

    /// <summary>
    /// Stop service started during class initialize and kill the thread
    /// </summary>
    [ClassCleanup]
    public void CleanupSwiperTests() {
        m_SwiperWS.Stop();
    }


    /// <summary>
    ///   simulate init, swipe, clear operations
    /// </summary>
    [TestMethod]
    public void TestSwiperService()
    {
        MessageBox.Show("test");
    }
}
}
BartoszKP
  • 34,786
  • 15
  • 102
  • 130
Amit Pal
  • 10,604
  • 26
  • 80
  • 160
  • 1
    Are you still getting the exact same error after adding the assembly reference to `Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll`? – Joachim Isaksson Nov 28 '12 at 10:36

13 Answers13

162

You have to add reference to

Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll 

It can be found at C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\ directory (for VS2010 professional or above; .NET Framework 4.0).

or right click on your project and select: Add Reference... > .NET: or click Add Reference... > .NET:

GabLeRoux
  • 16,715
  • 16
  • 63
  • 81
Agent007
  • 2,720
  • 3
  • 20
  • 24
  • 2
    Why was this accepted? The comments seem to indicate it was unhelpful. Could someone elaborate? – sirdank May 11 '15 at 14:11
  • @sirdank You do realise that no one but the OP can accept an answer as the solution, don't you? If it weren't helpful for the OP, he wouldn't have accepted it. – Agent007 May 12 '15 at 04:06
  • 6
    @Agent007 I know. However, the OP leaving a comment indicating it didn't work suggests (to me at least) that something more needs to be done. After figuring out what else needed to be done, not leaving a comment describing such seems unhelpful. – sirdank May 12 '15 at 13:09
  • 8
    Just had this issue, and this answer was the solution. Anyone have any insight as to why this is the case? Why is the namespace `Microsoft.VisualStudio.TestTools.UnitTesting` and the assembly is `Microsoft.VisualStudio.QualityTools.UnitTestFramework`? Why could they not name them both the same thing? – Alan Thomas Oct 05 '16 at 16:34
  • One way that I got tripped up was that when Team Build builds it will look in a different folder depending upon the version. Microsoft Visual Studio 10.0 for VS 2010, Microsoft Visual Studio 12.0 for VS 2013, Microsoft Visual Studio 14.0 for VS 2015. – Ryan Gates Nov 08 '16 at 21:53
  • @sirdank You must build, even with fail, the solution first to resolve the reference. At least in VS 2017. – Oyvind Andersson Jun 12 '17 at 11:44
  • I didn't have a "PublicAssemblies" folder for VS Community 2017-only a "PrivateAssemblies" folder, and it wasn't located in there-in fact, that folder was empty except for `Connectivity.xml`. It wasn't in my list of .NET assemblies like pictured above, either. – vapcguy Aug 22 '18 at 17:34
  • The IDE adds a relative path with ..\..\..\..\, etc. More robust to change it like this: $(DevEnvDir)PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll – Scott Hutchinson May 24 '22 at 21:57
126

I know this is old, this is what came up in my Google search. I needed to reference these packages on NuGet:

enter image description here

Jesse Sierks
  • 2,258
  • 3
  • 19
  • 30
  • 3
    In my case (VS2019) I needed to upgrade these packages then it fixed the problem. Cheers! – RJFalconer Feb 06 '20 at 22:40
  • 2
    For me adding the PackageReference for MSTest.TestFramework didi the trick. I didn't need to reference the TestAdapter. (I'd guess the latter is for tools integration. E.g.: autdiscovery of tests.) But yea, that was exactly the answer I needed. Thanks! – Michael Jul 21 '21 at 19:10
  • 2
    You need to ensure that these packages are the same version. If you upgrade one without the other your tests won't work. Why the hell these are two separate packages only God and Bill Gates can answer.... – Liam Oct 29 '21 at 12:39
  • 3
    This needs to be marked as the answer – Nagendra Nov 30 '21 at 02:54
  • 2
    Odd ball here in VS2022 too. It works as a charm. – Marcelo Scofano Diniz May 13 '22 at 17:04
  • "Why the hell these are two separate packages only God and Bill Gates can answer...." A) Bill gates doesnt run MIcrosoft (hasnt for a long time), B) the TestAdapter nuget package is for integration into appropriate TestRunners, like VSTest.console but not MSTest.console which is deprecated. – enorl76 Aug 23 '23 at 17:48
18

The DLL you're looking for that contains that namespace is

Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

Note that unit testing cannot be used in Visual Studio Express.

Community
  • 1
  • 1
Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
12

To resolve this issue, I had to do the following:

  1. Launch the Visual Studio Installer with administrative privileges
  2. If it prompts you to install updates to Visual Studio, do so before continuing
  3. When prompted, click the button to Modify the existing installation
  4. Click on the "Individual components" tab / header along the top
  5. Scroll down to the "Debugging and testing" section
  6. Check the box next to "Web performance and load testing tools"
  7. Click the Modify button on the bottom right corner of the dialog to install the missing DLLs

Once the DLLs are installed, you can add references to them using the method that Agent007 indicated in his answer.

S. Hooley
  • 284
  • 3
  • 9
  • 1
    "Web performance and load testing tools" no longer appears. What would you recommend we select instead? – Shafiq Jetha Nov 27 '18 at 19:50
  • @ShafiqJetha, I still see the option for "Web performance and load testing tools". I'm using Visual Studio Enterprise 2017 - 15.8.9. What version are you using? It looks like Microsoft has changed the interface of the installer slightly since I wrote the post above. When I launch the Visual Studio Installer (running it as Administrator), I click the "More" button to the right of the "Update" and "Launch" buttons, then select "Modify", then resume with step 4 in the list in my post above. – S. Hooley Nov 28 '18 at 16:30
  • I'm using the Build Tools installer for Visual Studio 2017, so that might explain it. – Shafiq Jetha Nov 28 '18 at 21:32
  • @ShafiqJetha what did you end up using? – Vin Shahrdar Mar 24 '20 at 22:25
  • @VinShahrdar I honestly can't remember; this was such a long time ago. I think we worked around the problem maybe by using someone else's NuGet package to get the required DLLs. Or maybe we saved the DLL to the repo. I honestly can't remember, sorry. – Shafiq Jetha Mar 25 '20 at 13:16
  • 1
    This is the correct answer. – Matt M Oct 13 '21 at 19:23
10

There is also a nice nuget package. It will pull the dll to your packages folder. You will need to add the reference to the dll manually.

NOTE: This package is not an official Microsoft package.

Rashack
  • 4,667
  • 2
  • 26
  • 35
  • 1
    The nuget package failed to install in project for .net 4.0 with VS2013. The only option for version was 11.0.50727.1. – WebComer Jun 08 '17 at 21:21
  • 1
    can anyone say if this nuget is truly Microsoft owned? It appears to be a personal nuget containing Microsoft asemblies – BozoJoe Aug 01 '17 at 22:20
  • This says it's for VS 2012 and it says "The owner has unlisted this package". – Aaron Franke Aug 23 '21 at 20:41
10

If you are using Visual Studio 2017 Community, the location is:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\v2.0

The DLL you want is there: Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

Apparently it is located in the C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\ directory for Visual Studio 2010 Professional version, but take note that the 10.0 will change to correspond with the release year, i.e. VS 2013 was version 12.0, VS 2015 was version 14.0, VS 2017 is 15.0. (VS Express is not supported and would require installing the NUnit NuGet package, through the NuGet Package Manager, instead.)

You go to References, right-click, select Add Reference, Browse. Navigate to the path, then double-click the file.

Then, you need a using statement at the top of your Unit Test class:

using Microsoft.VisualStudio.TestTools.UnitTesting;

vapcguy
  • 7,097
  • 1
  • 56
  • 52
0

I.e. for Visual Studio 2013 I would reference this assembly:

Microsoft.VisualStudio.Shell.14.0.dll

You can find it i.e. here:

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Extensions\BugAid Software\BugAid\1.0

and don't forget to implement:

using Microsoft.VisualStudio;

creg
  • 154
  • 3
  • 13
0

If you came here because your VSTS build job is failing with the above error message. Ensure that you are using at least version 2.* of the nuget task to restore your packages.

Jim Wolff
  • 5,052
  • 5
  • 34
  • 44
  • Do you know why version 2.* is needed? We're on TFS 2017 and are running into this error. – DylanSp Dec 21 '18 at 16:21
  • I just lifted the code from QA to UAT and I'm now testing the SAME unittests, on the SAME computer, in the same Parent folder in practically the same solution. but nooo.. No unittest suddenly found.... I'm so tired of Microsofts Path hell they have created in the later years. – Christian Jul 16 '20 at 13:36
0

I got this problem after moving a project and deleting it's packages folder. Nuget was showning that MSTest.TestAdapter and MSTest.TestFramework v 1.3.2 was installed. The fix seemed to be to open VS as administrator and build After that I was able to re-open and build without having admin priviledge.

Kirsten
  • 15,730
  • 41
  • 179
  • 318
0

Add a reference to 'Microsoft.VisualStudio.QualityTools.UnitTestFramework" NuGet packet and it should successfully build it.

  • I'm sure the other seven entries suggesting this exact solution, doesn't get through to the readers. Repetition is even better when you repeat it. – Christian Jul 16 '20 at 13:38
0

With Visual Studio 2019, running a .net core 3.1 project, you will need to install the latest test framework to resolve the error.

Easiest way to accomplish this is by hovering the browser over a [Test] annotation (underlined in red) and select suggested fixes. The one needed is to "search for and install the latest test framework."

0

Make sure you have the Microsoft Visual Studio Test Platform extension installed (In Visual Studio 2017 -> Tools -> Extensions and Updates)

Extensions Screenshot

Then you can add the refernece to the dll at:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\Extensions\TestPlatform\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

Pat
  • 2,540
  • 1
  • 21
  • 28
-4

Simply Refer this URL and download and save required dll files @ this location:

C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies

URL is: https://github.com/NN---/vssdk2013/find/master

Tommy Grovnes
  • 4,126
  • 2
  • 25
  • 40
Veer
  • 5