我可以在不安装 Visual Studio 的情况下使用 mstest.exe 吗?

发布于 2024-09-12 09:19:55 字数 100 浏览 5 评论 0原文

我想使用 mstest.exe 在生成服务器上运行单元测试,但我不想在生成服务器上安装 Visual Studio。我可以只安装 MSTest 而不使用 Visual Studio 吗?

I want to use mstest.exe to run my unit test on build server, but I don't want to install Visual Studio on the build server. Can I just install MSTest without Visual Studio?

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

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

发布评论

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

评论(8

花开半夏魅人心 2024-09-19 09:19:56

如果您需要运行 mstest.exe webtest 工具,那么您可以安装 Visual Studio Enterprise 试用版,并确保在运行测试的帐户下至少运行一次(只需启动它),无需执行任何其他操作。因此,如果您的测试在系统帐户下运行,那么您需要使用如下所示的内容

PS C:\agent> psexec -s cmd.exe
C:\Windows\system32>"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\mstest.exe"
Microsoft (R) Test Execution Command Line Tool Version 15.0.27520.0
Copyright (c) Microsoft Corporation. All rights reserved.

Please specify tests to run, or specify the /publish switch to publish results.
For switch syntax, type "MSTest /help"

If you need to run mstest.exe webtest tool then you can install Visual Studio Enterprise trial and make sure to run it at least once (just start it) under account under which test will be running with nothing additional needs to be done. So if your test run under System account then you need to use something like below

PS C:\agent> psexec -s cmd.exe
C:\Windows\system32>"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\mstest.exe"
Microsoft (R) Test Execution Command Line Tool Version 15.0.27520.0
Copyright (c) Microsoft Corporation. All rights reserved.

Please specify tests to run, or specify the /publish switch to publish results.
For switch syntax, type "MSTest /help"
薄荷梦 2024-09-19 09:19:56

MSTest 是 针对 .NET Core 用户发布。该公告包含 dotnet 工具的使用示例。我还没有弄清楚如何获取独立的 mstest 可执行文件。

MSTest was announced for .NET Core users. The announcement has usage example with the dotnet tool. I haven't figured myself how to get the standalone mstest executable.

梦在深巷 2024-09-19 09:19:55

无需 Visual Studio 即可运行 mstest.exe。
下载以下 Visual Studio ISO 代理之一,并在服务器上安装测试代理

这将安装所需的所有内容从命令行运行 mstest.exe,比 Visual Studio 轻得多。如果我没记错的话,下载约 500mb,安装测试代理约 300mb。

It is possible to run mstest.exe without visual studio.
Download one of the Agents for Visual Studio ISO's below and install the Test Agent on the server:

This installs everything needed for running mstest.exe from the command line and is much lighter weight than visual studio. ~500mb download and around ~300mb to install just the test agent if I remember correctly.

少年亿悲伤 2024-09-19 09:19:55

此答案特别适用于 Visual Studio 2017,答案是。请参阅此答案了解如何找到MSBuild.exe和/或MSTest.exe 可执行文件。

  • 如果您只需要构建单元测试项目,请安装包MSTest.TestFramework 进入这些项目,并从中删除对 Microsoft.VisualStudio.QualityTools.UnitTestFramework 的引用。现在您所需要做的就是安装 Visual Studio 2017 构建工具 并调用 msbuild.exe执行构建。
  • 如果您还需要运行测试,事情就会变得更加棘手:
    • 最简单的解决方案是安装VS2017社区版(其中包括msbuild和mstest) - 但我不确定这是否合法,而且我不是律师,所以要小心!
    • 合法上更安全的解决方案(就磁盘空间而言更轻)是安装Visual Studio 2017 测试代理然后 Visual Studio 2017 构建工具准确的顺序至关重要1);这将为您提供 MSTest.exevstest.console.exe,然后您可以调用它们。请注意,实际弄清楚这些可执行文件所在的位置是一件很痛苦的事情,因为它们不会与构建工具中的 MSBuild.exe 存在于同一目录结构中。

最后,也是非常重要的一点:如果您确实使用 MSTest.TestFramework 并且仍然需要能够在 Visual Studio IDE 中发现和运行测试,那么您还需要 MSTest.TestAdapter 安装在单元测试项目中。

1:虽然 VS2017 支持并行安装,但它使用仅记录最近安装的单个注册表项。因此,如果您最后安装 Test Agent,该注册表项将指向其安装目录...但 Test Agent 不包含 MSBuild.exe,因此任何依赖此注册表项的代码都无法识别该可执行文件的路径将会失败。任何人都在猜测为什么 Microsoft 不能将测试代理作为构建工具的可选部分(以便所有 EXE 都位于同一目录层次结构中)。

This answer pertains specifically to Visual Studio 2017, and the answer is yes. Please refer to this answer as to how to locate the MSBuild.exe and/or MSTest.exe executables.

  • If you only need to build your unit test project(s), install the package MSTest.TestFramework into those project(s) and remove the reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework from them. Now all you need is to install the Visual Studio 2017 Build Tools and invoke msbuild.exe to perform the build.
  • If you need to run your tests as well, things become trickier:
    • The simplest solution is to install VS2017 Community Edition (which includes both msbuild and mstest) - but I am unsure of the legality of this, and am not a lawyer, so be careful!
    • A legally safer solution (and far lighter, in terms of disk space) is to install the Visual Studio 2017 Test Agent and then Build Tools for Visual Studio 2017 (exact order is vital1); this will give you MSTest.exe and vstest.console.exe which you can then call out to. Do note that actually figuring out where these executables reside is a pain, because they won't exist in the same directory structure as MSBuild.exe in Build Tools.

Finally, and very importantly: if you do use MSTest.TestFramework and still need to be able to discover and run tests from within the Visual Studio IDE, you'll also need MSTest.TestAdapter installed in your unit test project(s).

1: While VS2017 supports side-by-side installs, it uses a single registry key that only records the most recent install. Hence, if you install Test Agent last, the key will point to its install directory... but Test Agent doesn't include MSBuild.exe, so any code that relies on this registry key to figure out that executable's path, will fail. Why Microsoft couldn't have made the Test Agent an optional part of Build Tools (so that all the EXEs live in the same directory hierarchy) is anyone's guess.

旧街凉风 2024-09-19 09:19:55

@crocpulsar,您需要在构建服务器上安装 Visual Studio,但不需要购买额外的许可证

构建和构建有太多的依赖项。 MSTest 可以在没有安装 VS 的情况下工作,而且它绝对不受支持。

只要启动构建的人拥有许可证,构建服务器就不需要许可证。从 2005 年的黑暗时期开始就是这样,只要有版本对等就可以了。

如果您团队中的每个人都拥有 Ultimate,那么您可以自由地将其安装在构建服务器上;但如果您的团队成员之一拥有 Premium,那么您最好在构建服务器上安装 Premium。这还支持许多其他功能,例如代码覆盖率、测试影响分析和架构验证等。

@crocpulsar, you need to install Visual Studio on your build server, but you do NOT need to buy an additional licence.

There are just way too many dependencies to getting build & MSTest to work without VS installed, and it is most definitely not supported.

As long as the person who starts the build has a license, you do not need one for the build server. This has been the case since the dark days of 2005, and as long as there is edition parity then you are OK.

If everyone in your team has Ultimate, then you are free to install it on the build server; but if one of your team member's has Premium, then you should ideally install Premium on the build server. This also enables lots of other bits like Code Coverage, Test Impact Analysis, and Architecture Validation among others.

不疑不惑不回忆 2024-09-19 09:19:55

我想你可能可以,但绝对不支持。

我发现这篇博客文章是由某人撰写的,他声称 MSTest 在没有安装 Visual Studio 的情况下也能工作。

I think you probably can, but its definitely not supported.

I've found this blog article written by someone who claims to have MSTest working without Visual Studio installed.

好听的两个字的网名 2024-09-19 09:19:55

我刚刚在我的服务器上运行了此功能,而没有安装 Visual Studio 2017 IDE。我的要求是

  • 构建项目
  • 构建测试项目
  • 使用 VSTest 运行测试(我相信这是 MSTest 的类似过程)

我必须结合其他答案中所述的一些事情,然后再做另一件事 此处

VS2017:

  1. BuildTools - 可以在 Microsoft 下载页面 上找到,然后向下滚动到“Visual Studio 2017 工具”-> “Visual Studio 2017 构建工具”
  2. TestAgent - 这可以在 Microsoft 下载页面 上找到,然后向下滚动到“ Visual Studio 2017 工具”-> “Visual Studio 2017 代理”
  3. Nuget 包 包含 Visual Studio 单元测试 DLL - 可以在 此处找到

步骤 3 是修复以下问题:

“无法解析此引用。无法找到程序集“Microsoft.VisualStudio.QualityTools.UnitTestFramework””

,然后导致:

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

我不必向项目添加任何引用。但是,vstest.console.exe 的路径包含在 TestAgent 文件夹中(对我来说,它是“C:\Program Files (x86)\Microsoft Visual Studio\2017\TestAgent\Common7\IDE\CommonExtensions\Microsoft\TestWindow” )

I just got this working on my servers without installing the Visual Studio 2017 IDE. My requirement was

  • Build projects
  • Build test projects
  • Run tests using VSTest (I believe it is a similar process for MSTest)

I had to do a combination of a few things stated in other answers and then also another one here.

VS2017:

  1. BuildTools - This can be found on the Microsoft downloads page, and then scroll down to "Tools for Visual Studio 2017" -> "Build Tools for Visual Studio 2017"
  2. TestAgent - This can be found on the Microsoft downloads page, and then scroll down to "Tools for Visual Studio 2017" -> "Agents for Visual Studio 2017"
  3. Nuget Package to include the visual studio unit testing dll - This can be found here

Step 3 was to fix the following issue:

"Could not resolve this reference. Could not locate the assembly "Microsoft.VisualStudio.QualityTools.UnitTestFramework""

Which then caused:

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

I did not have to add any references to the project. However, the path to the vstest.console.exe is contained in the TestAgent folder (for me it was "C:\Program Files (x86)\Microsoft Visual Studio\2017\TestAgent\Common7\IDE\CommonExtensions\Microsoft\TestWindow")

月隐月明月朦胧 2024-09-19 09:19:55

以下是我在不安装 VS 2012 的情况下让构建服务器运行 MsTest 所采取的步骤:

  1. 在 c:\dev 中创建“Mstest”目录文件夹。
  2. 将“Mstest.exe”和“Mstest.exe.config”从 C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE 复制到“Mstest”目录
  3. 将 Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll 复制到“Mstest” ' 目录
  4. 在 'Mstest' 文件夹中创建 'assemblies' 目录
  5. 将所有 v11 Microsoft.VisualStudio.QualityTools.*.dll 从 C:\Windows\ assembly 提取到 'Mstest/assemblies' 目录
  6. 复制所有 'v11' Microsoft.VisualStudio.QualityTools.< em>.dlls 和 Microsoft.VisualStudio.TestTools..dlls 从 C:\Windows\Microsoft.NET\ assembly\GAC_MSIL 到 'Mstest/assemblies'
  7. 复制所有 v11 Microsoft.VisualStudio.QualityTools..dlls和 Microsoft.VisualStudio.TestTools.dll 从 C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies 到 'Mstest/assemblies'
  8. 将 'assemblies' 添加到 'privatePath' 属性在“Mstest.exe.config”中
  9. 导出“HKEY_LOCAL_MACHINE/SOFTWARE/Wow6432Node/Microsoft/VisualStudio/11.0/Enterprise/QualityTools”并将其应用到 hudson 框。
  10. 将 QTAgent32.exe 和 QTAgent32.exe.config 从 C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE 复制到“MsTest”目录
  11. 将“assemblies”添加到“QTAgent32.exe”的“privatePath”属性中。 config'
  12. 将 'msdia110.dll' 从 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Packages\Debugger' 复制到 'MsTest/assemblies'
  13. 使用 c:/windows 注册 'msdia110.dll' /syswow64/regsvr32.exe /i '../mstest/assemblies/msdia110.dll'(这引发了一个错误,但由于某种原因它仍然有效。我运行了几次并在检查之前尝试了不同的 regsvr32.exe 版本,但它在注册表中)

  14. 添加环境变量“MSTEST_HOME”并将其设置为“c:\dev\” mstest\' 或您的路径。我在构建脚本中使用了环境变量。

调试MsTest执行错误:

添加到“MsTest.exe.config”

<system.diagnostics> 
  <trace autoflush="true" indentsize="4"> 
    <listeners> 
      <add name="EqtListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\MsTest.log" /> 
    </listeners> 
  </trace> 
  <switches> 
    <add name="EqtTraceLevel" value="Verbose" /> 
  </switches> 
</system.diagnostics>

Here are the steps I took to get my build server to run MsTest without installing VS 2012:

  1. Created 'Mstest' directory folder in c:\dev.
  2. Copied 'Mstest.exe' and 'Mstest.exe.config' from C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE to 'Mstest' directory
  3. Copy Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll to 'Mstest' directory
  4. Created 'assemblies' directory in 'Mstest' folder
  5. Extracted all v11 Microsoft.VisualStudio.QualityTools.*.dlls from C:\Windows\assembly to 'Mstest/assemblies' directory
  6. Copy all 'v11' Microsoft.VisualStudio.QualityTools..dlls and Microsoft.VisualStudio.TestTools..dlls from C:\Windows\Microsoft.NET\assembly\GAC_MSIL to 'Mstest/assemblies'
  7. Copy all v11 Microsoft.VisualStudio.QualityTools..dlls and Microsoft.VisualStudio.TestTools..dll from C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PrivateAssemblies to 'Mstest/assemblies'
  8. Add 'assemblies' to the 'privatePath' attribute of in 'Mstest.exe.config'
  9. Export 'HKEY_LOCAL_MACHINE/SOFTWARE/Wow6432Node/Microsoft/VisualStudio/11.0/Enterprise/QualityTools and apply it to hudson box.
  10. Copy QTAgent32.exe and QTAgent32.exe.config to 'MsTest' directory from C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE
  11. Add 'assemblies' to the 'privatePath' attribute of in 'QTAgent32.exe.config'
  12. Copy 'msdia110.dll' from 'C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\Packages\Debugger' to 'MsTest/assemblies'
  13. Register 'msdia110.dll' with c:/windows/syswow64/regsvr32.exe /i '../mstest/assemblies/msdia110.dll'(This threw an error, but for some reason it still worked. I ran it a couple times and tried different regsvr32.exe versions before I checked, but it's there in the registry)

  14. Add environment variable 'MSTEST_HOME' and set it to 'c:\dev\mstest\' or to your path. I used the environment variable in my build script.

Debugging MsTest execution error:

Add to 'MsTest.exe.config'

<system.diagnostics> 
  <trace autoflush="true" indentsize="4"> 
    <listeners> 
      <add name="EqtListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\MsTest.log" /> 
    </listeners> 
  </trace> 
  <switches> 
    <add name="EqtTraceLevel" value="Verbose" /> 
  </switches> 
</system.diagnostics>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文