gpt4 book ai didi

msbuild - MSBuild Exec 任务是否在 STDOUT 中搜索字符串 "error"?

转载 作者:行者123 更新时间:2023-12-04 18:21:29 27 4
gpt4 key购买 nike

我有一个带有单个忽略测试的小型 NUnit 测试套件。我现在正在编写一个简单的 MSBuild 脚本来恢复和发布等。我试图得到一个 dotnet test任务工作

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

但是,它每次都以代码 -1 退出!
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.

如果我直接在控制台中运行该命令,那就没问题了。
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 task在 STDOUT 中搜索某种错误消息,可能只是“错误”一词,以设置退出代码/状态。

这确实出现在我的控制台上(出于某种原因,NUnit 为忽略/跳过的测试打印“错误消息”)。
Skipped  FilterEndpointWithCompletelyFilteredSystemsReturnsNotFound("foo")
Error Message:
OneTimeSetUp: Having trouble constructing this scenario with the current command catalog

如果我注释掉这个测试,运行就会通过(通过 msbuild)。

我对 Exec 任务的看法正确吗?我会通过覆盖 CustomErrorRegularExpression 来“解决”问题吗?范围?我找不到关于这个参数的任何好的信息……我会把它设置为空字符串吗?

最佳答案

如果提供,Exec checks针对 CustomErrorRegularExpression 的输出和 CustomWarningRegularExpression第一的。如果这些不匹配或未提供,Exec然后 uses以下正则表达式:

            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
)

以以下格式计算行 example被解释为错误或警告(取决于这两个词中的哪个在“Cat.”部分)。

Main.cs(17,20):命令行警告 CS0168:声明了变量“foo”但从未使用过
-------------- -------------- ------- ------ ----------- ---------------------
起源子类别猫。代码文本

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



编辑

(我自己的问题:当我的第二句话直接与此矛盾时,为什么我最初说“是的”?)

不。 :) 设置 IgnoreStandardErrorWarningFormattrue .来自 documentation你在你的问题中链接:

IgnoreStandardErrorWarningFormat: Optional Boolean parameter.

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

The default value is false.

关于msbuild - MSBuild Exec 任务是否在 STDOUT 中搜索字符串 "error"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48117302/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com