MSBuild Exec任务是否在STDOUT中搜索字符串“错误"? [英] Does the MSBuild Exec task search STDOUT for the string "error"?

查看:83
本文介绍了MSBuild Exec任务是否在STDOUT中搜索字符串“错误"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有单个被忽略测试的小型NUnit测试套件.我现在正在编写一个简单的MSBuild脚本来还原和发布等.我试图使dotnet test任务正常工作

I have a small NUnit test suite with a single ignored test. I'm just now writing a simple MSBuild script to restore and publish and the like. I tried to get a dotnet test task working

<Target Name="test" DependsOnTargets="restore">
    <Exec Command="dotnet test"
          WorkingDirectory="test\Example.Tests" />
</Target>

但是,每次它都以代码-1退出!

But, it exits with code -1 every time!

PS> dotnet msbuild /t:test build.xml
Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

    Restore completed in 50.88 ms for C:\...\src\Example\Example.csproj.
    Restore completed in 57.18 ms for C:\...\test\Example.Tests\Example.Tests.csproj.
  Build started, please wait...
  Build completed.

  Test run for C:\...\test\Example.Tests\bin\Debug\netcoreapp1.1\Example.Tests.dll(.NETCoreApp,Version=v1.1)
  Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0
  Copyright (c) Microsoft Corporation.  All rights reserved.

        Starting test execution, please wait...
  NUnit Adapter 3.8.0.0: Test execution started
  Running all tests in C:\...\test\Example.Tests\bin\Debug\netcoreapp1.1\Example.Tests.dll
  NUnit3TestExecutor converted 26 of 26 NUnit test cases
  Skipped  FilterEndpointWithCompletelyFilteredSystemsReturnsNotFound("foo")
EXEC : error Message:  [C:\...\build.xml]
   OneTimeSetUp: Having trouble constructing this scenario with the current command catalog

  NUnit Adapter 3.8.0.0: Test execution complete

  Total tests: 26. Passed: 25. Failed: 0. Skipped: 1.
  Test Run Successful.
  Test execution time: 2.8322 Seconds


C:\...\build.xml(16,9): error MSB3073: The command "dotnet test" exited with code -1.

如果我直接在控制台中运行命令,就可以了.

If I run the command directly in my console, it's fine.

PS> dotnet test
Build started, please wait...
Build completed.

Test run for C:\...\test\Example.Tests\bin\Debug\netcoreapp1.1\Example.Tests.dll(.NETCoreApp,Version=v1.1)
Microsoft (R) Test Execution Command Line Tool Version 15.0.0.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
NUnit Adapter 3.8.0.0: Test execution started
Running all tests in C:\...\test\Example.Tests\bin\Debug\netcoreapp1.1\Example.Tests.dll
NUnit3TestExecutor converted 26 of 26 NUnit test cases
Skipped  FilterEndpointWithCompletelyFilteredSystemsReturnsNotFound("foo")
Error Message:
 OneTimeSetUp: Having trouble constructing this scenario with the current command catalog

NUnit Adapter 3.8.0.0: Test execution complete

Total tests: 26. Passed: 25. Failed: 0. Skipped: 1.
Test Run Successful.
Test execution time: 3.6485 Seconds

我四处寻找帮助,但没有发现任何明确的内容.我的印象是 Exec任务在STDOUT中搜索某种形式错误消息,可能只是单词"error",以设置退出代码/状态.

I searched around for help, but didn't quite find anything explicit. I got the impression that the Exec task searches STDOUT for some kind of error message, possibly just the word "error", in order to set the exit code/status.

这确实出现在我的控制台上(出于某些原因,NUnit会为忽略/跳过的测试打印错误消息".)

This does appear on my console (for some reason NUnit prints "Error Message" for ignored/skipped tests).

Skipped  FilterEndpointWithCompletelyFilteredSystemsReturnsNotFound("foo")
Error Message:
 OneTimeSetUp: Having trouble constructing this scenario with the current command catalog

如果我注释掉该测试,则运行通过(通过msbuild).

If I comment out this test, the run passes (via msbuild).

我对Exec任务正确吗?我将通过覆盖CustomErrorRegularExpression参数来解决"问题吗?我找不到有关此参数的任何好信息...我可以将其设置为空字符串吗?

Am I correct about the Exec task? Would I "fix" the problem by overriding the CustomErrorRegularExpression parameter? I can't find any good info about this parameter... would I set it to an empty string?

推荐答案

(如果提供),Exec 使用以下RegEx:

If provided, Exec checks the output against CustomErrorRegularExpression and CustomWarningRegularExpression first. If those do not match or were not provided, Exec then uses the following RegEx:

            new Regex
            (
            // Beginning of line and any amount of whitespace.
            @"^\s*"
                // Match a [optional project number prefix 'ddd>'], single letter + colon + remaining filename, or
                // string with no colon followed by a colon.
            + @"(((?<ORIGIN>(((\d+>)?[a-zA-Z]?:[^:]*)|([^:]*))):)"
                // Origin may also be empty. In this case there's no trailing colon.
            + "|())"
                // Match the empty string or a string without a colon that ends with a space
            + "(?<SUBCATEGORY>(()|([^:]*? )))"
                // Match 'error' or 'warning'.
            + @"(?<CATEGORY>(error|warning))"
                // Match anything starting with a space that's not a colon/space, followed by a colon.
                // Error code is optional in which case "error"/"warning" can be followed immediately by a colon.
            + @"( \s*(?<CODE>[^: ]*))?\s*:"
                // Whatever's left on this line, including colons.
            + "(?<TEXT>.*)$",
            RegexOptions.IgnoreCase | RegexOptions.Compiled
            )

以以下示例被解释为错误或警告(取决于这两个词中的哪一个在目录"部分中).

That works out lines in the format of the following example being interpreted as errors or warnings (depending which of those two words are in the "Cat." part).


Main.cs(17,20):Command line warning CS0168: The variable 'foo' is declared but never used
-------------- ------------ ------- ------  ----------------------------------------------
Origin         SubCategory  Cat.    Code    Text

我将通过重写CustomErrorRegularExpression参数来解决"该问题吗?

Would I "fix" the problem by overriding the CustomErrorRegularExpression parameter?

编辑

(对我自己的问题:为什么我的第二句话直接与 Earth 上的话说是"?)

(Question for myself: Why on Earth did I say "Yup" initially when my second sentence directly contradicts this?)

不. :)将IgnoreStandardErrorWarningFormat设置为true.从您在问题中链接的文档:

Nope. :) Set IgnoreStandardErrorWarningFormat to true. From the documentation you linked in your question:

IgnoreStandardErrorWarningFormat:可选的Boolean参数.

  • 如果为false,则在输出中选择与标准错误/警告格式匹配的行,并将其记录为错误/警告.
  • 如果true,请禁用此行为.
  • If false, selects lines in the output that match the standard error/warning format, and logs them as errors/warnings.
  • If true, disable this behavior.

默认值为false.

这篇关于MSBuild Exec任务是否在STDOUT中搜索字符串“错误"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆