cake: The MSTest tool doesn't pick up the mstest.exe from Visual Studio 2017

What You Are Seeing?

I run the unit tests like this:

MSTest("./src/**/bin/" + configuration + "/*.Tests.dll");

I get the following error when running the build script:

An error occurred when executing task 'Run-Unit-Tests'.
Error: MSTest: Could not locate executable.

What is Expected?

I expect my unit tests to run.

What version of Cake are you using?

0.17

Are you running on a 32 or 64 bit system?

64 bit

What environment are you running on? Windows? Linux? Mac?

Windows 10

Are you running on a CI Server? If so, which one?

No, just building on my local machine.

How Did You Get This To Happen? (Steps to Reproduce)

Run a build with unit tests on a machine with only Visual Studio 2017 (Community Edition).

Output Log

========================================
Run-Unit-Tests
========================================
Executing task: Run-Unit-Tests
An error occurred when executing task 'Run-Unit-Tests'.
Error: Cake.Core.CakeException: MSTest: Could not locate executable.
   at Cake.Core.Tooling.Tool`1.RunProcess(TSettings settings, ProcessArgumentBuilder arguments, ProcessSettings processSettings)
   at Cake.Core.Tooling.Tool`1.Run(TSettings settings, ProcessArgumentBuilder arguments, ProcessSettings processSettings, Action`1 postAction)
   at Cake.Core.Tooling.Tool`1.Run(TSettings settings, ProcessArgumentBuilder arguments)
   at Cake.Common.Tools.MSTest.MSTestRunner.Run(IEnumerable`1 assemblyPaths, MSTestSettings settings)
   at Cake.Common.Tools.MSTest.MSTestAliases.MSTest(ICakeContext context, IEnumerable`1 assemblyPaths, MSTestSettings settings)
   at Cake.Common.Tools.MSTest.MSTestAliases.MSTest(ICakeContext context, IEnumerable`1 assemblyPaths)
   at Cake.Common.Tools.MSTest.MSTestAliases.MSTest(ICakeContext context, String pattern)
   at Submission#0.<.ctor>b__11()
   at Cake.Core.CakeTaskBuilderExtensions.<>c__DisplayClass5_0.<Does>b__0(ICakeContext context)
   at Cake.Core.ActionTask.Execute(ICakeContext context)
   at Cake.Core.DefaultExecutionStrategy.Execute(CakeTask task, ICakeContext context)
   at Cake.Core.CakeEngine.ExecuteTask(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report)
   at Cake.Core.CakeEngine.RunTarget(ICakeContext context, IExecutionStrategy strategy, String target)
   at Cake.Scripting.BuildScriptHost.RunTarget(String target)
   at Submission#0..ctor(Session session, Object& submissionResult)
   at Submission#0.<Factory>(Session session)
   at Roslyn.Scripting.CommonScriptEngine.Execute[T](String code, String path, DiagnosticBag diagnostics, Session session, Boolean isInteractive)
   at Roslyn.Scripting.Session.Execute(String code)
   at Cake.Scripting.Roslyn.Stable.DefaultRoslynScriptSession.Execute(Script script)
   at Cake.Core.Scripting.ScriptRunner.Run(IScriptHost host, FilePath scriptPath, IDictionary`2 arguments)
   at Cake.Commands.BuildCommand.Execute(CakeOptions options)
   at Cake.CakeApplication.Run(CakeOptions options)
   at Cake.Program.Main()

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 19 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Looking forward to the fix. This is the workaround I’ve been using:

// https://github.com/cake-build/cake/issues/1522
VSTestSettings FixToolPath(VSTestSettings settings)
{
    #tool vswhere
    settings.ToolPath =
        VSWhereLatest(new VSWhereLatestSettings { Requires = "Microsoft.VisualStudio.PackageGroup.TestTools.Core" })
        .CombineWithFilePath(File(@"Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"));
    return settings;
}

Then just wrap your settings:

VSTest("**/*.Tests.dll", FixToolPath(new VSTestSettings { Foo = 42 }))

(See https://github.com/Microsoft/vswhere/wiki/Find-VSTest.)

I had the same issue - as @phillipsj already mentioned, the ToolPath did the trick (even it is not super “clean”)

MSTest(pathPattern, new MSTestSettings() { ....
                                 ToolPath = @"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\MSTest.exe" });