控制台应用程序内的 MSTest

发布于 2024-09-27 01:50:19 字数 415 浏览 0 评论 0原文

我试图在控制台应用程序中运行一些测试

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

我得到的错误是:

命名空间“Microsoft”中不存在类型或命名空间名称“VisualStudio”(您是否缺少程序集引用?)

但这一切都有效在一个单独的测试项目中: alt text

问题: 有什么不同?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月打碎记忆 2024-10-04 01:50:19

您需要将 ConsoleApplication 的目标框架更改为 .Net Framework 4NOT .NET Framework 4 Client Profile

如果您的目标是.NET
Framework 4 客户端配置文件,您不能
引用不在其中的程序集
.NET Framework 4 客户端配置文件。
相反,您必须以 .NET 为目标
框架4。

您无法引用 Microsoft.VisualStudio.QualityTools.UnitTestFramewor,因为它不是客户端配置文件框架的一部分。

编辑:抱歉,您已经有了...

您需要在控制台应用程序中引用Microsoft.VisualStudio.QualityTools.UnitTestFramework

您可以从 C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies 添加

它 默认的 Visual Studio Test 项目默认具有此引用...

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...

维持三分热 2024-10-04 01:50:19

您可以从 Visual Studio 创建测试项目,并将项目输出类型从类库更改为控制台应用程序。

问候
阿西姆·班萨尔

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

Regards
Aseem Bansal

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文