New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dukeofharen opened this Issue Mar 7, 2017 · 18 comments

Comments

Projects
None yet
9 participants
@dukeofharen

dukeofharen commented Mar 7, 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()
@dukeofharen

This comment has been minimized.

Show comment
Hide comment
@dukeofharen

dukeofharen Mar 7, 2017

I already had a peek in the source code and saw this piece of code in MSTest\MSTestRunner.cs:

private FilePath GetToolPath(string version)
{
	var programFiles = _environment.GetSpecialPath(SpecialPath.ProgramFilesX86);
	var root = programFiles.Combine(string.Concat("Microsoft Visual Studio ", version, "/Common7/IDE"));
	return root.CombineWithFilePath("mstest.exe");
}

This code assumes a specific path format, but it seems the format has been changed for Visual Studio 2017 (Community).
Old: Microsoft Visual Studio 14.0\Common7\IDE
New: Microsoft Visual Studio\2017\Community\Common7\IDE

I might send a pull request, as soon as I have time and I have the source code building :P

dukeofharen commented Mar 7, 2017

I already had a peek in the source code and saw this piece of code in MSTest\MSTestRunner.cs:

private FilePath GetToolPath(string version)
{
	var programFiles = _environment.GetSpecialPath(SpecialPath.ProgramFilesX86);
	var root = programFiles.Combine(string.Concat("Microsoft Visual Studio ", version, "/Common7/IDE"));
	return root.CombineWithFilePath("mstest.exe");
}

This code assumes a specific path format, but it seems the format has been changed for Visual Studio 2017 (Community).
Old: Microsoft Visual Studio 14.0\Common7\IDE
New: Microsoft Visual Studio\2017\Community\Common7\IDE

I might send a pull request, as soon as I have time and I have the source code building :P

@phillipsj

This comment has been minimized.

Show comment
Hide comment
@phillipsj

phillipsj Mar 8, 2017

Collaborator

Great catch! Don't know why I didn't consider this when adding the MSBuild support for 2017. Temporarily you should be able to set the toolpath in the settings file. Let me know if you would like some assistance on the pull request, more than happy to help.

Collaborator

phillipsj commented Mar 8, 2017

Great catch! Don't know why I didn't consider this when adding the MSBuild support for 2017. Temporarily you should be able to set the toolpath in the settings file. Let me know if you would like some assistance on the pull request, more than happy to help.

@phillipsj

This comment has been minimized.

Show comment
Hide comment
@phillipsj

phillipsj Mar 8, 2017

Collaborator

I meant you can set the ToolPath in the MSTestSettings class that you pass.

Collaborator

phillipsj commented Mar 8, 2017

I meant you can set the ToolPath in the MSTestSettings class that you pass.

@gep13

This comment has been minimized.

Show comment
Hide comment
@gep13

gep13 Mar 8, 2017

Member

@dukeofharen to be clear, using this: Microsoft Visual Studio\2017\Community\Common7\IDE directly, isn't going to work. That path looks specific to the Community Edition of Visual Studio, and likely be different in the higher SKU's. As a result, any PR to correct this would need to delve a little deeper into finding the new location.

Member

gep13 commented Mar 8, 2017

@dukeofharen to be clear, using this: Microsoft Visual Studio\2017\Community\Common7\IDE directly, isn't going to work. That path looks specific to the Community Edition of Visual Studio, and likely be different in the higher SKU's. As a result, any PR to correct this would need to delve a little deeper into finding the new location.

@dukeofharen

This comment has been minimized.

Show comment
Hide comment
@dukeofharen

dukeofharen Mar 8, 2017

I've found this article about someone having problems locating the IDE folder: http://www.visualstudioextensibility.com/2016/11/23/some-implications-of-the-new-modular-setup-of-visual-studio-2017-for-vsx-developers/

You can install multiple versions of Visual Studio 2017 next to eachother. As far as I can tell, you only have the Community, Professional and Enterprise editions. Would it be OK to just check the existence of any of these 3 folders?

dukeofharen commented Mar 8, 2017

I've found this article about someone having problems locating the IDE folder: http://www.visualstudioextensibility.com/2016/11/23/some-implications-of-the-new-modular-setup-of-visual-studio-2017-for-vsx-developers/

You can install multiple versions of Visual Studio 2017 next to eachother. As far as I can tell, you only have the Community, Professional and Enterprise editions. Would it be OK to just check the existence of any of these 3 folders?

@devlead

This comment has been minimized.

Show comment
Hide comment
@devlead

devlead Mar 8, 2017

Member

User can install in any drive, multiple versions is possible - especially if you have the build tools installed. But we could of course check the possible default paths first.

@phillipsj couldn't these paths also derive from the work done in #1520?

Member

devlead commented Mar 8, 2017

User can install in any drive, multiple versions is possible - especially if you have the build tools installed. But we could of course check the possible default paths first.

@phillipsj couldn't these paths also derive from the work done in #1520?

@gep13

This comment has been minimized.

Show comment
Hide comment
@gep13

gep13 Mar 8, 2017

Member

@devlead I was going to ask the same question, i.e. if the vswhere.exe could help.

Member

gep13 commented Mar 8, 2017

@devlead I was going to ask the same question, i.e. if the vswhere.exe could help.

@phillipsj

This comment has been minimized.

Show comment
Hide comment
@phillipsj

phillipsj Mar 8, 2017

Collaborator
Collaborator

phillipsj commented Mar 8, 2017

@robertmuehsig

This comment has been minimized.

Show comment
Hide comment
@robertmuehsig

robertmuehsig Mar 13, 2017

Contributor

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" });
Contributor

robertmuehsig commented Mar 13, 2017

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" });
@masterkawaster

This comment has been minimized.

Show comment
Hide comment
@masterkawaster

masterkawaster Jul 3, 2017

I think similar problem is for VSTest
https://github.com/cake-build/cake/blob/develop/src/Cake.Common/Tools/VSTest/VSTestRunner.cs (at the bottom)
The default path (for professional) should be: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe

masterkawaster commented Jul 3, 2017

I think similar problem is for VSTest
https://github.com/cake-build/cake/blob/develop/src/Cake.Common/Tools/VSTest/VSTestRunner.cs (at the bottom)
The default path (for professional) should be: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe

@epot

This comment has been minimized.

Show comment
Hide comment
@epot

epot Jul 17, 2017

Any chance this is going to be fixed soon?

epot commented Jul 17, 2017

Any chance this is going to be fixed soon?

@devlead

This comment has been minimized.

Show comment
Hide comment
@devlead

devlead Jul 17, 2017

Member

@epot I've now marked issue up for grabs.
If someone want to take a stab at creating a PR let us know on this issue.

Member

devlead commented Jul 17, 2017

@epot I've now marked issue up for grabs.
If someone want to take a stab at creating a PR let us know on this issue.

@epot

This comment has been minimized.

Show comment
Hide comment
@epot

epot Jul 17, 2017

Ok, thanks :)

epot commented Jul 17, 2017

Ok, thanks :)

@phillipsj

This comment has been minimized.

Show comment
Hide comment
@phillipsj

phillipsj Oct 8, 2017

Collaborator

@devlead @gep13 I am getting back into the swing of things and if this is still an issue, I will take it.

Collaborator

phillipsj commented Oct 8, 2017

@devlead @gep13 I am getting back into the swing of things and if this is still an issue, I will take it.

@bertvansteen

This comment has been minimized.

Show comment
Hide comment
@bertvansteen

bertvansteen Oct 24, 2017

@phillipsj If you didn't start on it yet I would like to allocate some time tomorrow to add MSTest 2017 support and prepare a pull request.

bertvansteen commented Oct 24, 2017

@phillipsj If you didn't start on it yet I would like to allocate some time tomorrow to add MSTest 2017 support and prepare a pull request.

@phillipsj

This comment has been minimized.

Show comment
Hide comment
@phillipsj

phillipsj Oct 24, 2017

Collaborator

@bertvansteen nope, not yet. Take it if you want it.

Collaborator

phillipsj commented Oct 24, 2017

@bertvansteen nope, not yet. Take it if you want it.

bertvansteen pushed a commit to bertvansteen/cake that referenced this issue Oct 25, 2017

@jnm2

This comment has been minimized.

Show comment
Hide comment
@jnm2

jnm2 Nov 3, 2017

Contributor

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

Contributor

jnm2 commented Nov 3, 2017

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

devlead added a commit to bertvansteen/cake that referenced this issue Nov 30, 2017

ecampidoglio added a commit to ecampidoglio/Linker that referenced this issue Dec 5, 2017

Sets the path to the VSTest executable
This is a temporary workaround until cake-build/cake#1522 is solved.

ecampidoglio added a commit to ecampidoglio/Linker that referenced this issue Dec 5, 2017

Sets the path to the VSTest executable
This is a temporary workaround until cake-build/cake#1522 is solved.

ecampidoglio added a commit to ecampidoglio/Linker that referenced this issue Dec 5, 2017

Sets the path to the VSTest executable
This is a temporary workaround until cake-build/cake#1522 is solved.

devlead added a commit to bertvansteen/cake that referenced this issue Dec 27, 2017

@devlead devlead closed this in 19a08c3 Dec 28, 2017

devlead added a commit that referenced this issue Dec 28, 2017

@devlead devlead added Improvement and removed Up-for-grabs labels Dec 28, 2017

@devlead devlead added this to the v0.24.0 milestone Dec 28, 2017

@jnm2

This comment has been minimized.

Show comment
Hide comment
@jnm2

jnm2 Jan 3, 2018

Contributor

Maybe this was in the wrong place for VSTest, but I was redirected by #1763 (comment).

In 0.24.0, VSTest is still not being located by Cake and I'm still forced to use the workaround above.

Contributor

jnm2 commented Jan 3, 2018

Maybe this was in the wrong place for VSTest, but I was redirected by #1763 (comment).

In 0.24.0, VSTest is still not being located by Cake and I'm still forced to use the workaround above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment