我的代码中有一个类,我不想出现在代码覆盖率数字中.我将[ExcludeFromCodeCoverage]属性添加到类定义中,如下所示:
[ExcludeFromCodeCoverage]
public class MyClass { ... }
Run Code Online (Sandbox Code Playgroud)
根据文档(http://msdn.microsoft.com/en-us/library/system.diagnostics.codeanalysis.excludefromcodecoverageattribute.aspx),这应该是我所需要的,但该类仍然出现在代码覆盖率分析中.
如果重要的话,我正在使用VS2012/.NET 4.5.
任何想法为什么这不起作用?
如果我有一个<ProjectReference>引用,有没有办法将条件编译值传递给该项目?像这样的东西(我知道<DefineConstants>这样不存在,只是为了说明需要):
<ProjectReference Include="..\DataProducer\DataProducer.csproj">
<DefineConstants>WAS_SET</DefineConstants>
<ProjectReference>
Run Code Online (Sandbox Code Playgroud)
因此,如果该项目中有一个类,如下所示:
public sealed class ProduceValue
{
public string Produce()
{
#if WAS_SET
return "WAS SET";
#else
return "NOTHING WAS SET";
#endif
}
}
Run Code Online (Sandbox Code Playgroud)
然后通过在编译期间传递该值,我可以获得不同的输出.