-
Notifications
You must be signed in to change notification settings - Fork 340
Create a proper MSBuild ToolTask based VSTestTask #2702
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
Create a proper MSBuild ToolTask based VSTestTask #2702
Conversation
Please note that I would be happy to answer any questions and/or reservations, and/or discuss any suggestions or improvements on this PR. |
Thank you for the contribution @mcartoixa, I'll check this during the week and ask my questions, if any. |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
569e421
to
cefe13d
Compare
I just rebased this PR against the |
|
||
activeProcess.WaitForExit(); | ||
Tracing.Trace("VSTest: Exit code: " + activeProcess.ExitCode); | ||
return activeProcess.ExitCode == 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should only return !Log.HasLoggedErrors
. The task should fail if and only if it has logged any errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is the way it's usually done in MSBuild tasks. Does vstest.console.exe
return an error code even in cases of success?
Anyway this task is a copy (mostly left unchanged) of the current one, kept here for compatibility purposes. The goal of this PR is rather to introduce a new task that would be more respectful of MSBuild, see VSTestTask
(the diff is rather useless on that one, though).
|
||
if (!string.IsNullOrEmpty(this.VSTestFramework)) | ||
{ | ||
Console.WriteLine(Resources.TestRunningSummary, this.TestFileFullPath, this.VSTestFramework); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A task shouldn't use Console.WriteLine, but instead use Log.LogMessage:
https://source.dot.net/#Microsoft.Build.Tasks.Core/Copy.cs,255
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed in general, but this has been left unchanged for compatibility with current behavior. The goal of this PR is rather to introduce a new task that would be more respectful of MSBuild, see VSTestTask
.
// Avoid logging "Task returned false but did not log an error." on test failure, because we don't | ||
// write MSBuild error. https://github.com/dotnet/msbuild/blob/51a1071f8871e0c93afbaf1b2ac2c9e59c7b6491/src/Framework/IBuildEngine7.cs#L12 | ||
var allowfailureWithoutError = BuildEngine.GetType().GetProperty("AllowFailureWithoutError"); | ||
allowfailureWithoutError?.SetValue(BuildEngine, true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should really not do this. If there was an error, log an MSBuild error. If there wasn't an error, don't log it.
Let's remove this reflection logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been left unchanged for compatibility with current behavior. The goal of this PR is rather to introduce a new task that would be more respectful of MSBuild, see VSTestTask
.
Just to make it clear to me. The |
@MarkKharitonov Right. |
cefe13d
to
7acb932
Compare
Just rebased again against |
When can we expect some kind of decision about the future of this PR? As mentioned before quite a few bugs could be affected by this.
|
7acb932
to
b6dcdc8
Compare
It took me 2 days to set up a new barely working development environment, but I think I managed to rebase this PR against |
d1e30d4
to
1b4b548
Compare
Any update on the status of this request? |
nit: file should be renamed too! test/Microsoft.TestPlatform.Build.UnitTests/VsTestTaskTests.cs -> VSTestTaskTests.cs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall I like it. It's a welcome change but a huge breaking change nonetheless, so its up to the owners, I think!
@Nirmal4G Thanks for the review! There is nothing more that I would like than having a discussion with the owners. Meanwhile it seems that I will have to rebase this PR again... |
Description
Update from nohwnd:
A new task VSTestTask2 and a logger MSBuildLogger (for internal use only) was added. And can be enabled by setting
/p:VsTestUseMSBuildOutput=true
.This is not enabled anywhere by default, neither in dotnet test, or under vstest, because I want to collect some feedback first.
The current console forwarding task has been renamed VSTestForwardingTask. The new VSTestTask, based on ToolTask, properly integrates into the MSBuild framework.
If the
$(VSTestUseConsole)
property is set toTrue
during the build, the old console forwarding VSTestForwardTask is used: logs are lost but output is colorized (like today). Otherwise the new VSTestTask is used: logs are fine but colorization is lost (except for errors, that are properly recognized by MSBuild).A new PR will be submitted right away on the dotnet/sdk project so that
dotnet test
sets the$(VSTestUseConsole)
property.In effect:
dotnet test
(like today).dotnet msbuild -Target:VSTest
.This PR feels more like a workaround than a proper fix: it still feels weird to depend on a MSBuild task (VSTestForwardingTask) that is not entirely MSBuild friendly... But it seems like the easiest fix that is compatible with the old behavior.
A proper fix would probably center around the implementation of
dotnet test
which could calldotnet exec vstest.console.dll
directly (in addition to MSBuild, for the build part only). This would render current workarounds like for dotnet/msbuild#3130, orAllowFailureWithoutError
definitely obsolete.Related issue
Fixes (or at least gives an option around) #680, #1503, #2224, dotnet/sdk#9481, dotnet/msbuild#5387 and probably more...
This is a new attempt after #2437.