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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3402899/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 12:18:37  来源:igfitidea点击:

Can I use mstest.exe without installing Visual Studio?

visual-studiomstestbuild-server

提问by yang-qu

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?

我想使用 mstest.exe 在构建服务器上运行我的单元测试,但我不想在构建服务器上安装 Visual Studio。我可以在没有 Visual Studio 的情况下安装 MSTest 吗?

回答by Bela

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 Agenton the server:

可以在没有 Visual Studio 的情况下运行 mstest.exe。
下载下面的 Visual Studio ISO代理之一并在服务器上安装测试代理

Visual Studio 2017(127MB disk space, less than that for download)
Visual Studio 2015(128MB setup, 2GB disk space required)
Visual Studio 2012(224MB)
Visual Studio 2013(287MB)
Visual Studio 2010(515MB)

Visual Studio的2017年(127MB硬盘空间,小于下载)
的Visual Studio 2015年(128MB的设置,需要2GB磁盘空间)
的Visual Studio 2012(224MB)
的Visual Studio 2013(287MB)
的Visual Studio 2010(515MB)

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.

这会安装从命令行运行 mstest.exe 所需的一切,并且比 Visual Studio 轻得多。如果我没记错的话,大约 500mb 下载和大约 300mb 安装测试代理。

UPDATE

更新

For versions older than VS 2017, look here:

对于 VS 2017 之前的版本,请看这里:

https://www.visualstudio.com/vs/older-downloads/

https://www.visualstudio.com/vs/older-downloads/

回答by Ian Kemp

This answer pertains specifically to Visual Studio 2017, and the answer is yes. Please be aware, however, that Microsoft (still) doesn't provide any sort of official API for locating the relevant executables (MSBuild.exeand MSTest.exe), so you are stuck reading registry keys and/or probing various directories to locate these files. You've been warned.

此答案专门针对 Visual Studio 2017,答案是yes。但是请注意,Microsoft(仍然)没有提供任何类型的官方 API 来定位相关的可执行文件(MSBuild.exeMSTest.exe),因此您不得不阅读注册表项和/或探查各种目录来定位这些文件。你已经被警告了。

  • If you only need to buildyour unit test project(s), install the package MSTest.TestFrameworkinto those project(s) and remove the reference to Microsoft.VisualStudio.QualityTools.UnitTestFrameworkfrom them. Now all you need is to install the Visual Studio 2017 Build Toolsand invoke msbuild.exeto perform the build.
  • If you need to runyour 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 Agentand thenBuild Tools for Visual Studio 2017(exact order is vital1); this will give you MSTest.exeand vstest.console.exewhich 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.exein Build Tools.
  • 如果您只需要构建单元测试项目,请将包安装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.exeBuild Tools存在于相同的目录结构中。

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

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

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.

1:虽然 VS2017 支持并行安装,但它使用一个仅记录最近安装的注册表项。因此,如果您最后安装测试代理,该键将指向其安装目录...但测试代理不包括MSBuild.exe,因此任何依赖此注册表项来确定可执行文件路径的代码都将失败。为什么微软不能让测试代理成为构建工具的可选部分(这样所有的 EXE 都存在于相同的目录层次结构中)是任何人的猜测。

回答by Justin

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.

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

回答by MrHinsh - Martin Hinshelwood

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

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

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

在没有安装 VS 的情况下让 build & MSTest 工作的依赖太多了,而且绝对不支持。

As long as the person who starts the build has a licence, 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.

只要开始构建的人有许可证,构建服务器就不需要许可证。自 2005 年的黑暗时期以来就是这种情况,只要有版本平价,就可以了。

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.

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

回答by Andy

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

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

  • Build projects
  • Build test projects
  • Run tests using VSTest (I believe it is a similar process for MSTest)
  • 构建项目
  • 构建测试项目
  • 使用 VSTest 运行测试(我相信这与 MSTest 的过程类似)

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

我必须结合其他答案中陈述的几件事,然后再结合此处的另一件事。

VS2017:

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 Packageto include the visual studio unit testing dll - This can be found here
  1. BuildTools- 这可以在Microsoft 下载页面上找到,然后向下滚动到“Visual Studio 2017 工具”->“Visual Studio 2017 构建工具”
  2. TestAgent- 这可以在Microsoft 下载页面上找到,然后向下滚动到“Visual Studio 2017 工具”->“Visual Studio 2017 代理”
  3. 包含 Visual Studio 单元测试 dll 的Nuget 包- 可在此处找到

Step 3 was to fix the following issue:

第 3 步是修复以下问题:

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

“无法解析此引用。无法找到程序集“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?) "

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

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")

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

回答by Dai Le

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

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

  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.

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

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

Debugging MsTest execution error:

调试 MsTest 执行错误:

Add to 'MsTest.exe.config'

添加到“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>

回答by user7610

MSTest was announced for .NET Coreusers. The announcement has usage example with the dotnettool. I haven't figured myself how to get the standalone mstestexecutable.

MSTest 是为 .NET Core用户发布的。该公告有该dotnet工具的使用示例。我还没有想好如何获得独立的mstest可执行文件。

回答by Gregory Suvalian

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

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

PS C:\agent> psexec -s cmd.exe
C:\Windows\system32>"C:\Program Files (x86)\Microsoft Visual Studio17\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"