从Visual Studio Team Services中的代码覆盖范围中排除程序集 [英] Excluding assemblies from code coverage in Visual Studio Team Services

查看:99
本文介绍了从Visual Studio Team Services中的代码覆盖范围中排除程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Visual Studio Team Services(以前称为Visual Studio Online)上运行的版本。我想从代码覆盖率计算中排除某些程序集。根据我已经阅读的格式 很多 来源。我创建了一个.runsettings文件,如下所示:

I have a build running on Visual Studio Team Services (formerly Visual Studio Online). I want to exclude some of the assemblies from code coverage calculations. Based on a format I've read from many sources. I have created a .runsettings file as follows:

<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
  <DataCollectionRunSettings>
    <DataCollectors>
      <DataCollector friendlyName="Code Coverage" 
          uri="datacollector://Microsoft/CodeCoverage/2.0"
          assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
        <Configuration>
          <CodeCoverage>
            <ModulePaths>
              <Exclude>
                <ModulePath>*AWSSDK*</ModulePath>
              </Exclude>
            </ModulePaths>
          </CodeCoverage>
        </Configuration>
      </DataCollector>
    </DataCollectors>
  </DataCollectionRunSettings>
</RunSettings>

但这会产生以下错误:

开始执行测试,请等待...
错误:System.InvalidOperationException:无法在流程流上混合同步和异步操作。
在System.Diagnostics.Process.get_StandardError()
在Microsoft.VisualStudio.Coverage.Vanguard.Wait()
在Microsoft.VisualStudio.Coverage.Vanguard.Start(字符串outputName,DataCollectionContext上下文)Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollectorImpl.StartVanguard(DataCollectionContext context)中的
Microsoft.VisualStudio.Coverage.UnitTestDataCollector.SessionStart(Object sender,SessionStartEventArgs e)中的
Microsoft.VisualStudio.Coverage中的
.DynamicCoverageDataCollector.SessionStart(Object sender,SessionStartEventArgs e)
at System.EventHandler`1.Invoke(Object sender,TEventArgs e)WEX.TestExecution.TaefDataCollectionEvents.OnSessionStart(SessionStartEventArgs e)
在WEX.TestExecution.DataCollectorTestMode.Initialize(ITestModeSettings设置,ICallbackRegistrar callbackRegistrar)
信息:此外,如果测试发现者&可以尝试指定'/ UseVsixExtensions'命令。 executor作为vsix扩展安装在计算机上,您的安装支持vsix扩展。示例:vstest.console.exe myTests.dll / UseVsixExtensions:true
VSTest测试运行失败,退出代码:1

Starting test execution, please wait... Error: System.InvalidOperationException: Cannot mix synchronous and asynchronous operation on process stream. at System.Diagnostics.Process.get_StandardError() at Microsoft.VisualStudio.Coverage.Vanguard.Wait() at Microsoft.VisualStudio.Coverage.Vanguard.Start(String outputName, DataCollectionContext context) at Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollectorImpl.StartVanguard(DataCollectionContext context) at Microsoft.VisualStudio.Coverage.UnitTestDataCollector.SessionStart(Object sender, SessionStartEventArgs e) at Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector.SessionStart(Object sender, SessionStartEventArgs e) at System.EventHandler`1.Invoke(Object sender, TEventArgs e) at WEX.TestExecution.TaefDataCollectionEvents.OnSessionStart(SessionStartEventArgs e) at WEX.TestExecution.DataCollectorTestMode.Initialize(ITestModeSettings settings, ICallbackRegistrar callbackRegistrar) Information: Additionally, you can try specifying '/UseVsixExtensions' command if the test discoverer & executor is installed on the machine as vsix extensions and your installation supports vsix extensions. Example: vstest.console.exe myTests.dll /UseVsixExtensions:true VSTest Test Run failed with exit code: 1

是,某些测试正在使用异步/等待。相同的.runsettings文件在Visual Studio 2015中可以正常工作。如果按照建议的方式操作并添加以下选项: / UseVsixExtensions:true ,则结果相同。我该如何解决?

Yes, some of the tests are using async/await. The same .runsettings file works fine in Visual Studio 2015. If I do as it suggests and add the following option: /UseVsixExtensions:true, the result is the same. How can I fix this?

推荐答案

runsettings文件使用以下正则表达式来匹配文件:

The runsettings file use following regex expressions to match the files:


正则表达式包含和排除节点使用正则表达式。
有关更多信息,请参见在Visual Studio中使用正则表达式。
正则表达式与通配符不同。特别是:

Regular expressions Include and exclude nodes use regular expressions. For more information, see Using Regular Expressions in Visual Studio. Regular expressions are not the same as wildcards. In particular:

。*匹配任何字符的字符串

.* matches a string of any characters

。匹配点。。)

()匹配括号(

\匹配文件路径分隔符 \

\ matches a file path delimiter "\"

^匹配字符串的开头

$匹配字符串的结尾

使用原始路径,由于路径中只有 *,因此将排除所有文件。有关详细信息,请参见此链接: Visual Studio中的正则表达式

With your original path, all the files will be excluded since you have only "*" in the path. Refer to this link for details: Regular Expressions in Visual Studio.

对于严重的例外,根据您提供的日志,您正在使用Hosted Build Agent运行构建。我对Hosted Build Agent进行了快速测试,并且也可以重现此问题。但是,当我尝试使用自己的生成代理时,不会发生此问题。我怀疑托管生成代理上的某些设置/配置会导致此问题,并且我可以帮助您在Microsoft Connect页面上提交反馈。您可以检查此链接以进行跟踪:从托管生成代理运行测试时无效的异常

For the bad exception, According to the logs your provided, you are running the build with Hosted Build Agent. I did a quick test with Hosted Build Agent and can reproduce this issue too. However this issue does not occur when I try with my own build agent. I suspect that there is some setting/configuration on Hosted Build Agent cause this issue and I have help your submit a feedback on Microsoft Connect Page. You can check this link for tracking: Invalid exception when run testing from Hosted Build Agent

这篇关于从Visual Studio Team Services中的代码覆盖范围中排除程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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