C# 在哪里可以找到缺少 dll 的“Microsoft.VisualStudio.TestTools.UnitTesting”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13602508/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Where to find "Microsoft.VisualStudio.TestTools.UnitTesting" missing dll?
提问by Amit Pal
I am getting following error in my C# visual studio project:
我在 C# Visual Studio 项目中遇到以下错误:
The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
命名空间“Microsoft”中不存在类型或命名空间名称“VisualStudio”(您是否缺少程序集引用?)
I also tried to find the microsoft.dll file but couldn't get any reference. Am I searching the wrong DLL?
我也试图找到 microsoft.dll 文件,但找不到任何参考。我是否在搜索错误的 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");
}
}
}
采纳答案by Agent007
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).
可以在“C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\”目录下找到(VS2010专业版以上;.NET Framework 4.0)。
or right click on your project and select: Add Reference... > .NET:

或右键单击您的项目并选择:添加引用... > .NET:

回答by Joachim Isaksson
The DLL you're looking for that contains that namespace is
您要查找的包含该命名空间的 DLL 是
Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
Note that unit testing cannot be used in Visual Studio Express.
请注意,不能在 Visual Studio Express 中使用单元测试。
回答by Rashack
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.
还有一个不错的nuget 包。它会将 dll 拉到您的包文件夹中。您将需要手动添加对 dll 的引用。
NOTE: This package is not an official Microsoft package.
注意:此包不是官方的 Microsoft 包。
回答by Veer
Simply Refer this URL and download and save required dll files @ this location:
只需参考此 URL 并在此位置下载并保存所需的 dll 文件:
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies
URL is: https://github.com/NN---/vssdk2013/find/master
网址是: https://github.com/NN---/vssdk2013/find/master
回答by creg
I.e. for Visual Studio 2013 I would reference this assembly:
即对于 Visual Studio 2013 我会参考这个程序集:
Microsoft.VisualStudio.Shell.14.0.dll
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
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;
使用 Microsoft.VisualStudio;
回答by Jesse Sierks
回答by S. Hooley
To resolve this issue, I had to do the following:
为了解决这个问题,我必须执行以下操作:
- Launch the Visual Studio Installer with administrative privileges
- If it prompts you to install updates to Visual Studio, do so before continuing
- When prompted, click the button to Modify the existing installation
- Click on the "Individual components" tab / header along the top
- Scroll down to the "Debugging and testing" section
- Check the box next to "Web performance and load testing tools"
- Click the Modify button on the bottom right corner of the dialog to install the missing DLLs
- 使用管理权限启动 Visual Studio 安装程序
- 如果它提示您安装 Visual Studio 更新,请在继续之前安装
- 出现提示时,单击按钮修改现有安装
- 单击顶部的“单个组件”选项卡/标题
- 向下滚动到“调试和测试”部分
- 选中“Web 性能和负载测试工具”旁边的框
- 单击对话框右下角的修改按钮以安装缺少的 DLL
Once the DLLs are installed, you can add references to them using the method that Agent007 indicated in his answer.
安装 DLL 后,您可以使用 Agent007 在其回答中指出的方法添加对它们的引用。
回答by vapcguy
If you are using Visual Studio 2017 Community, the location is:
如果您使用的是 Visual Studio 2017 社区,则位置为:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\ReferenceAssemblies\v2.0
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
你想要的 DLL 就在那里: 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.0will 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.)
显然它位于C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\Visual Studio 2010 Professional 版本的目录中,但请注意,它10.0会随着发布年份而变化,即 VS 2013 为 12.0 版,VS 2015 为 14.0 版,VS 2017 为 15.0。(不支持 VS Express,需要通过 NuGet 包管理器安装 NUnit NuGet 包。)
You go to References, right-click, select Add Reference, Browse. Navigate to the path, then double-click the file.
您转到References,右键单击,选择Add Reference , Browse。导航到该路径,然后双击该文件。
Then, you need a usingstatement at the top of your Unit Test class:
然后,您需要using在单元测试类的顶部声明:
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting;
回答by Jim Wolff
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.
如果您来到这里是因为您的 VSTS 构建作业失败并显示上述错误消息。确保您至少使用 nuget 任务的 2.* 版本来还原您的包。
回答by Kirsten Greed
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.
移动项目并删除它的包文件夹后,我遇到了这个问题。Nuget 显示已安装 MSTest.TestAdapter 和 MSTest.TestFramework v 1.3.2。修复似乎是以管理员身份打开VS并构建之后,我能够在没有管理员权限的情况下重新打开和构建。

