Exclude Attributes with MSBuild
Exclude Attributes with MSBuild
I am trying to exclude some methods and classes in our solution from NCover reporting using an attribute, based on the article here:
http://laribee.com/using-attributes-to-exclude-code-from-coverage
But I can't seem to apply the //ea paramater successfully in our MSBuild file.
We have two tasks in msbuild.xml:
I have tried putting the CommanLineArgs and ExcludeAttributes in the NCoverReporting task, but it crashes.
With these in the CoverMyCode, the build succeeds, but methods and classes with the Common.NoCoverage attribute still appear in the reporting and stats.
Can anybody see what is wrong, or what I am leaving out?
Thanks very much.
RE: Exclude Attributes with MSBuild
Most likely the issue is that you're not using the full name of the attribute class. Does using a value of "Common.NoCoverageAttribute" get things working?
Also, Microsoft added an attribute to System.Diagnostics as of .NET 4, so you can use "System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute" if you're using .NET 4, rather than having to write your own attribute.
RE: Exclude Attributes with MSBuild
Thanks for the reply.
Unfortunately using "Common.NoCoverageAttribute" does not change the reporting, the classes and methods still appear.
Can you think of anything else that I may have left out??
Thanks for the tip about .Net 4! We are not quite there yet..
Nathan
RE: Exclude Attributes with MSBuild
Dumb question, but did you rerun coverage after you changed the attribute?
Also, is Common.NoCoverageAttribute the full typename (namespace and all) of the attribute? ExcludeAttribute has to use the full name of the attribute's type.
RE: Exclude Attributes with MSBuild
Yeah, actually it's a good question. When I look at the symbol coverage report in TeamCity, at the top, it says 'Coverage generated on: 28/02/2010 at 1:00:07 AM' which is obviously old, while the 'Report generated on: 9/07/2010 at 1:04:35 AM' which is expected.
So the question is, how do we get it to generate new coverage data. I thought it would do that when the solution is built in TeamCity, but that seems not to be the case.
That is the full path to the attribute, and I have tried both including and excluding the word 'Attribute' at the end.
Thanks for your suggestions so far.
RE: Exclude Attributes with MSBuild
What happens if you change the NCoverReporting task attribute that reads:
CoverageDataPaths="Tests\Output\Coverage*unitcoverage.xml"
to be:
CoverageDataPaths="Tests\Output\Coverage\${BUILD_NUMBER}unitcoverage.xml"
Using the wildcard would merge all of those files, which would cause the exclusions to still not show up for the earlier files.
RE: Exclude Attributes with MSBuild
Thanks for the suggestion, it worked and now the Symbol Coverage report shows the expected date and time.
I still cannot get the attribute to apply to the reporting, as classes and methods with the attribute still appear in the Full Coverage reporting (and I suspect are being included in the Symbol Coverage stats).
Anything else we could check or try?
RE: Exclude Attributes with MSBuild
nathanford,
We'd like to help you get this straightened out. Please email support (support@ncover.com) with a verbose coverage log. To create the log, add the following to your NCover task in your MSBuild script:
LogFile="coverage.log" LogLevel="Verbose"
In your email, include the names of some classes & methods to be excluded so we can work our way back through the log to see what is happening.
One last thing--please include the NCover specific sections of your current MSBuild script.
Thanks for using NCover!
RE: Exclude Attributes with MSBuild
Thanks so much for the offer. I had another look at this problem today, and I noticed that we had these on the NCover task:
CommandLineArgs="//ea Common.NoCoverageAttribute" ExcludeAttributes="Common.NoCoverage"
So I changed the 'ExcludeAttributes' to: ExcludeAttributes="Common.NoCoverageAttribute"
And it started picking up the attribute. It's weird that the CommandLineArgs doesn't seem to be having an effect. But at least we now have some accurate stats to work with.
Thanks very much for your attention and help!
RE: Exclude Attributes with MSBuild
nathanford,
Those argument names can be confusing. CommandLineArgs is the argument provided to the app that the tests are exercising. NCover gets passed the ExcludeAttributes argument. That is why you were not receiving accurate stats before your latest changes.
Glad to hear things are working now! Please let me know if I can help further. Happy coding.