Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net C#Msbuild代码覆盖率未达到阈值时硬停止_.net_C# 4.0_Msbuild_Nunit - Fatal编程技术网

.net C#Msbuild代码覆盖率未达到阈值时硬停止

.net C#Msbuild代码覆盖率未达到阈值时硬停止,.net,c#-4.0,msbuild,nunit,.net,C# 4.0,Msbuild,Nunit,我们有一个包含多个项目的c#解决方案。项目使用msbuild进行打包,运行Nunit进行单元测试。我们目前没有的是为每个项目定义代码覆盖率阈值,如果代码覆盖率低于阈值限制,则msbuild将失败。这在java项目中是现成的,使用maven和cobertura作为插件。 网络世界中的任何这样的工具 我们正在使用 -Visual Studio 2017专业版 -Msbuild 15.3.409.57025 -Resharper旗舰2017.2 -dotnetframework4.6.2 -Nunit

我们有一个包含多个项目的c#解决方案。项目使用msbuild进行打包,运行Nunit进行单元测试。我们目前没有的是为每个项目定义代码覆盖率阈值,如果代码覆盖率低于阈值限制,则msbuild将失败。这在java项目中是现成的,使用maven和cobertura作为插件。 网络世界中的任何这样的工具

我们正在使用 -Visual Studio 2017专业版 -Msbuild 15.3.409.57025 -Resharper旗舰2017.2 -dotnetframework4.6.2
-Nunit 2.5.7

如果您使用的是ReSharper,则可以使用DotCover作为代码覆盖工具。此工具可以生成一个报告,然后可以使用生成目标对该报告进行分析,以使生成失败

<Target Name="FailBuildOnLowCoverage">

    <!-- $(DotCoverResult) is the text of the report that you obtained by reading the report file -->

    <PropertyGroup>
      <CodeCoverageValue>$([System.Text.RegularExpressions.Regex]::Match($(DotCoverResult), '(?&lt;="Total",)(.*?)(?=[,])'))</CodeCoverageValue>
      <CodeCoverageValue Condition="'$(CodeCoverageValue)' == ''">0</CodeCoverageValue>
    </PropertyGroup>


<Message Condition="'$(CodeCoverageValue)' &lt; '30'" Text="Code coverage is less than 30%!

░░░░░░░░░░░█████████████
░░░░░░░░░███░███░░░░░░██
███░░░░░██░░░░██░██████████
████████░░░░░░████░░░░░░░██
████░░░░░░░░░░██░░██████████
████░░░░░░░░░░░███░░░░░░░░░██
████░░░░░░░░░░░██░░██████████
████░░░░░░░░░░░░████░░░░░░░░█
████░░░░░░░░░░░░░███░░████░░█
█████████░░░░░░░░░░████░░░░░█
███░░░░░██░░░░░░░░░░░░░█████
░░░░░░░░░███░░░░░░░██████
░░░░░░░░░░░██░░░░░░██
░░░░░░░░░░░░███░░░░░██
░░░░░░░░░░░░░░██░░░░██
░░░░░░░░░░░░░░░███░░░██
░░░░░░░░░░░░░░░░░██░░░█
░░░░░░░░░░░░░░░░░░█░░░█
░░░░░░░░░░░░░░░░░░██░██
░░░░░░░░░░░░░░░░░░░███
" />

$([System.Text.RegularExpressions.Regex]::匹配($(DotCoverResult),'(?=“Total”,)(.*?(=[,]))
0

谢谢你,迈克尔。。我会试试这个。